feat(practice): queue practice runs with one running and ten waiting
This commit is contained in:
1 parent
51770eea6c
commit
754c745fba
40 files changed
+3040
-70
No files matched your search
@@ -42,6 +42,9 @@ func TestAssessmentPracticeSubmissionStorage(t *testing.T) {
|
||||
})
|
||||
owner := newPracticeCandidate(ctx, t, harness, "practice-owner", 10)
|
||||
other := newPracticeCandidate(ctx, t, harness, "practice-other", 20)
|
||||
// firstRun is the debug run that the first case stores; it stays queued,
|
||||
// as no worker runs here, until a later case gives it a result.
|
||||
var firstRun uuid.UUID
|
||||
|
||||
t.Run("debug run is stored with its job and shows no hidden content", func(t *testing.T) {
|
||||
body := practiceRunBody(t, owner.practiceID, "python", practiceSource, []domain.PracticeTest{{Input: "4 5\n", ExpectedOutput: "9\n"}})
|
||||
@@ -58,6 +61,7 @@ func TestAssessmentPracticeSubmissionStorage(t *testing.T) {
|
||||
}
|
||||
assertPracticeResponseIsPublic(t, created)
|
||||
assertPracticeRows(t, ctx, harness.pool, owner.practiceID, "public", 1)
|
||||
firstRun = run.ID
|
||||
|
||||
replay := practiceRunRequest(t, harness, owner, body, "run-first")
|
||||
if replay.Code != http.StatusAccepted || decodePracticeRun(t, replay).ID != run.ID {
|
||||
@@ -90,15 +94,9 @@ func TestAssessmentPracticeSubmissionStorage(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("a stored result is shown without hidden groups", func(t *testing.T) {
|
||||
body := practiceRunBody(t, owner.practiceID, "go", "package main\nfunc main() {}\n", nil)
|
||||
created := practiceRunRequest(t, harness, owner, body, "run-with-result")
|
||||
if created.Code != http.StatusAccepted {
|
||||
t.Fatalf("create run = %d %s", created.Code, created.Body.String())
|
||||
}
|
||||
run := decodePracticeRun(t, created)
|
||||
// A result that holds a hidden group, which a debug run never gets,
|
||||
// proves that the presentation drops it.
|
||||
storePracticeResult(t, ctx, harness.pool, run.ID, domain.PracticeRunResult{
|
||||
storePracticeResult(t, ctx, harness.pool, firstRun, domain.PracticeRunResult{
|
||||
Outcome: domain.PracticeOutcomeWrongAnswer, DurationMs: 42,
|
||||
Groups: []domain.PracticeGroupOutcome{
|
||||
{ID: practice.PublicGroupID, Outcome: domain.PracticeOutcomeWrongAnswer, PassedTests: 1, TotalTests: 2, Tests: []domain.PracticeTestOutcome{
|
||||
@@ -108,7 +106,7 @@ func TestAssessmentPracticeSubmissionStorage(t *testing.T) {
|
||||
{ID: "hidden-1", Hidden: true, Outcome: domain.PracticeOutcomeAccepted, PassedTests: 1, TotalTests: 1},
|
||||
},
|
||||
})
|
||||
read := practiceRunRead(t, harness, owner, owner.attemptID, run.ID)
|
||||
read := practiceRunRead(t, harness, owner, owner.attemptID, firstRun)
|
||||
finished := decodePracticeRun(t, read)
|
||||
if read.Code != http.StatusOK || finished.State != "finished" || finished.Result == nil || len(finished.Result.Tests) != 2 {
|
||||
t.Fatalf("finished run = %d %s", read.Code, read.Body.String())
|
||||
@@ -196,6 +194,8 @@ type practiceHarness struct {
|
||||
*assessmentAttemptHTTPHarness
|
||||
service *practice.Service
|
||||
passwordHash domain.PasswordHash
|
||||
// databaseURL names the isolated database of the harness.
|
||||
databaseURL string
|
||||
}
|
||||
|
||||
// newPracticeHarness builds the router on an isolated, migrated database with
|
||||
@@ -225,7 +225,9 @@ func newPracticeHarness(
|
||||
if err != nil {
|
||||
t.Fatalf("HashNewPassword() error = %v", err)
|
||||
}
|
||||
return &practiceHarness{assessmentAttemptHTTPHarness: attemptHarness, service: service, passwordHash: passwordHash}
|
||||
return &practiceHarness{
|
||||
assessmentAttemptHTTPHarness: attemptHarness, service: service, passwordHash: passwordHash, databaseURL: databaseURL,
|
||||
}
|
||||
}
|
||||
|
||||
// practiceCandidate is a candidate whose real attempt is at its main practice.
|
||||
|
||||
Reference in new issue
Block a user