Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scripts/test-runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ done
# Get logs and get rid of containers
logs=$(docker logs jury-testing)
docker compose -f docker-compose.test.yml down
printf "$logs"

# If no failed lines, exit with success
failed=$(echo "$logs" | grep "failed")
if [[ -z "$failed" ]]; then
echo "Success :)"
printf "\n\nSuccess :)\n"
exit 0
fi

# Otherwise, exit with failure
printf "$logs"
printf "\n\n###################################\n##### THERE ARE TEST FAILURES #####\n###################################\n"
exit 1
4 changes: 2 additions & 2 deletions server/router/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func PauseClock(ctx *gin.Context) {

// Send OK
state.Logger.AdminLogf("Paused clock")
ctx.JSON(http.StatusOK, gin.H{"clock": state.Clock.State})
ctx.JSON(http.StatusOK, gin.H{"clock": state.Clock.State, "ok": 1})
}

// POST /admin/clock/unpause - UnpauseClock unpauses the clock
Expand All @@ -163,7 +163,7 @@ func UnpauseClock(ctx *gin.Context) {

// Send OK
state.Logger.AdminLogf("Unpaused clock")
ctx.JSON(http.StatusOK, gin.H{"clock": state.Clock.State})
ctx.JSON(http.StatusOK, gin.H{"clock": state.Clock.State, "ok": 1})
}

// POST /admin/clock/reset - ResetClock resets the clock
Expand Down
27 changes: 18 additions & 9 deletions server/router/judge.go
Original file line number Diff line number Diff line change
Expand Up @@ -1019,13 +1019,14 @@ func MoveSelectedJudges(ctx *gin.Context) {
}

type AddJudgeFromQRRequest struct {
Code string `json:"code"`
Name string `json:"name"`
Email string `json:"email"`
Track string `json:"track"`
Code string `json:"code"`
Name string `json:"name"`
Email string `json:"email"`
Track string `json:"track"`
NoSend *bool `json:"no_send"`
}

// POST /judge/qr - Add a judge from a QR code
// POST /judge/qr/add - Add a judge from a QR code
func AddJudgeFromQR(ctx *gin.Context) {
// Get the state from the context
state := GetState(ctx)
Expand Down Expand Up @@ -1095,10 +1096,12 @@ func AddJudgeFromQR(ctx *gin.Context) {
}

// Send email to judge
err = funcs.SendJudgeEmail(judge, hostname)
if err != nil {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "error sending judge email: " + err.Error()})
return err
if qrReq.NoSend == nil || !*qrReq.NoSend {
err = funcs.SendJudgeEmail(judge, hostname)
if err != nil {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "error sending judge email: " + err.Error()})
return err
}
}

// Insert the judge into the database
Expand All @@ -1114,6 +1117,12 @@ func AddJudgeFromQR(ctx *gin.Context) {
return
}

// Guard against early transaction exit leaving judge nil
if judge == nil {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "unexpected error creating judge"})
return
}

// Send OK
track := ""
if qrReq.Track != "" {
Expand Down
17 changes: 4 additions & 13 deletions server/router/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package router

import (
"errors"
"fmt"
"net/http"
"server/database"
"server/funcs"
Expand Down Expand Up @@ -352,8 +351,6 @@ func DeleteProject(ctx *gin.Context) {
// Get the id from the request
id := ctx.Param("id")

fmt.Println("hello1")

// Convert judge ID string to ObjectID
projectObjectId, err := primitive.ObjectIDFromHex(id)
if err != nil {
Expand All @@ -370,43 +367,33 @@ func DeleteProject(ctx *gin.Context) {
return err
}

fmt.Println("hello2")

// Delete all instances of this project from judges' seen projects array and rankings
err = database.DeleteSeenProject(state.Db, sc, &projectObjectId)
if err != nil {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "error deleting instances of project from judges' seen project: " + err.Error()})
return err
}

fmt.Println("hello3")

// Delete all flags for this project
err = database.DeleteFlagsCascade(state.Db, sc, &projectObjectId, nil)
if err != nil {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "error deleting flags for project: " + err.Error()})
return err
}

fmt.Println("hello4")

return nil
})
if err != nil {
return
}

fmt.Println("hello3.5")

// Update all judge rankings
err = judging.InitAggregateRankings(state.Db)
if err != nil {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "error re-calculating aggregate rankings for all judges: " + err.Error()})
return
}

fmt.Println("hello5")

// Send OK
state.Logger.AdminLogf("Deleted project %s", id)
ctx.JSON(http.StatusOK, gin.H{"ok": 1})
Expand Down Expand Up @@ -803,6 +790,10 @@ func MoveProject(ctx *gin.Context) {
if err != nil {
return
}

// Send OK
state.Logger.AdminLogf("Moved project %s to table %d", id.Hex(), moveReq.Location)
ctx.JSON(http.StatusOK, gin.H{"ok": 1})
}

// POST /project/move - Move selected projects to a different group
Expand Down
6 changes: 4 additions & 2 deletions tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ module tests

go 1.23.1

require go.mongodb.org/mongo-driver v1.17.1
require (
github.com/valyala/fastjson v1.6.4
go.mongodb.org/mongo-driver v1.17.1
)

require (
github.com/golang/snappy v0.0.4 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/valyala/fastjson v1.6.4 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
Expand Down
14 changes: 7 additions & 7 deletions tests/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@ package main
import (
"context"
"os"
"tests/src"
"tests/tests"
"tests/util"
)

func main() {
// Initialize the logger (make sure to change the .gitignore if this filename ever changes)
logger := src.NewLogger("test-log.txt")
logger := util.NewLogger("test-log.txt")

// Log start message with date and time
logger.LogLn(src.Info, "\n===============\nTESTING STARTED\n===============")
logger.Log(src.Info, "Date/time: %s\n", src.GetDateTime())
logger.LogLn(util.Info, "\n===============\nTESTING STARTED\n===============")
logger.Log(util.Info, "Date/time: %s\n", util.GetDateTime())

// Initialize the database connection
db := src.InitDb(logger)
db := util.InitDb(logger)

// Close the database connection
defer db.Client().Disconnect(context.Background())

// Wait for backend to load
err := src.WaitForBackend(logger)
err := util.WaitForBackend(logger)
if err != nil {
os.Exit(1)
}

// Create a context with the database and logger
context := &src.Context{
context := &util.Context{
Db: db,
Logger: logger,
}
Expand Down
Loading
Loading