From be77f9ed593bb6aec0a35b617b059f920e6b4481 Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Tue, 5 May 2020 17:49:26 -0500 Subject: [PATCH] archiver: tests: Test* is run in a separate context than TestMain We must setup the mutex/cond variables at the beginning of any test that's going to use it, or else these will be nil when the test is actually ran. --- services/archiver/archiver_test.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/services/archiver/archiver_test.go b/services/archiver/archiver_test.go index 4c0ee4407d..63ef36fb0f 100644 --- a/services/archiver/archiver_test.go +++ b/services/archiver/archiver_test.go @@ -21,10 +21,6 @@ var queueMutex sync.Mutex func TestMain(m *testing.M) { models.MainTest(m, filepath.Join("..", "..")) - - archiveQueueMutex = &queueMutex - archiveQueueStartCond = sync.NewCond(&queueMutex) - archiveQueueReleaseCond = sync.NewCond(&queueMutex) } func allComplete(inFlight []*ArchiveRequest) bool { @@ -79,6 +75,15 @@ func releaseOneEntry(t *testing.T, inFlight []*ArchiveRequest) { func TestArchive_Basic(t *testing.T) { assert.NoError(t, models.PrepareTestDatabase()) + archiveQueueMutex = &queueMutex + archiveQueueStartCond = sync.NewCond(&queueMutex) + archiveQueueReleaseCond = sync.NewCond(&queueMutex) + defer func() { + archiveQueueMutex = nil + archiveQueueStartCond = nil + archiveQueueReleaseCond = nil + }() + ctx := test.MockContext(t, "user27/repo49") firstCommit, secondCommit := "51f84af23134", "aacbdfe9e1c4"