diff --git a/cmd/mothd/httpd_test.go b/cmd/mothd/httpd_test.go index f551df4..9ddee02 100644 --- a/cmd/mothd/httpd_test.go +++ b/cmd/mothd/httpd_test.go @@ -74,7 +74,7 @@ func TestHttpd(t *testing.T) { t.Error("Register failed", r.Body.String()) } - time.Sleep(TestMaintenanceInterval) + stateProvider.refresh() if r := hs.TestRequest("/state", nil); r.Result().StatusCode != 200 { t.Error(r.Result()) @@ -131,7 +131,6 @@ func TestHttpd(t *testing.T) { t.Error("Unexpected body", r.Body.String()) } - time.Sleep(TestMaintenanceInterval) stateProvider.refresh() if r := hs.TestRequest("/content/pategory/2/puzzle.json", nil); r.Result().StatusCode != 200 { @@ -149,7 +148,7 @@ func TestHttpd(t *testing.T) { log.Print(v) } - t.Errorf("Points log wrong length. Wanted 1, got %v", state.PointsLog) + t.Errorf("Points log wrong length. Wanted 1, got %v (length %d)", state.PointsLog, len(state.PointsLog)) } else if len(state.Puzzles["pategory"]) != 2 { t.Error("Didn't unlock next puzzle") } diff --git a/cmd/mothd/server_test.go b/cmd/mothd/server_test.go index 0c49285..92c8839 100644 --- a/cmd/mothd/server_test.go +++ b/cmd/mothd/server_test.go @@ -3,12 +3,10 @@ package main import ( "io/ioutil" "testing" - "time" "github.com/spf13/afero" ) -const TestMaintenanceInterval = time.Millisecond * 1 const TestTeamID = "teamID" // NewTestServer creates a new MothServer with NewTestMothballs and some initial state. @@ -17,17 +15,14 @@ const TestTeamID = "teamID" func NewTestServer() *MothServer { puzzles := NewTestMothballs() puzzles.refresh() - go puzzles.Maintain(TestMaintenanceInterval) state := NewTestState() afero.WriteFile(state, "teamids.txt", []byte("teamID\n"), 0644) afero.WriteFile(state, "messages.html", []byte("messages.html"), 0644) state.refresh() - go state.Maintain(TestMaintenanceInterval) theme := NewTestTheme() afero.WriteFile(theme.Fs, "/index.html", []byte("index.html"), 0644) - go theme.Maintain(TestMaintenanceInterval) return NewMothServer(Configuration{}, theme, state, puzzles) } @@ -54,6 +49,7 @@ func TestProdServer(t *testing.T) { teamID := TestTeamID server := NewTestServer() + state := server.State.(*State) handler := server.NewHandler(participantID, teamID) anonHandler := server.NewHandler("badParticipantId", "badTeamId") @@ -85,8 +81,7 @@ func TestProdServer(t *testing.T) { t.Error("index.html wrong contents", contents) } - // Wait for refresh to pick everything up - time.Sleep(TestMaintenanceInterval) + state.refresh() { es := handler.ExportState() @@ -139,7 +134,7 @@ func TestProdServer(t *testing.T) { t.Error("Right answer marked wrong", err) } - time.Sleep(TestMaintenanceInterval) + state.refresh() { es := handler.ExportState() @@ -168,7 +163,7 @@ func TestProdServer(t *testing.T) { t.Error("Right answer marked wrong:", err) } - time.Sleep(TestMaintenanceInterval) + state.refresh() { es := anonHandler.ExportState()