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.
This commit is contained in:
Kyle Evans 2020-05-05 17:49:26 -05:00
parent 759b4d1eec
commit be77f9ed59
1 changed files with 9 additions and 4 deletions

View File

@ -21,10 +21,6 @@ var queueMutex sync.Mutex
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
models.MainTest(m, filepath.Join("..", "..")) models.MainTest(m, filepath.Join("..", ".."))
archiveQueueMutex = &queueMutex
archiveQueueStartCond = sync.NewCond(&queueMutex)
archiveQueueReleaseCond = sync.NewCond(&queueMutex)
} }
func allComplete(inFlight []*ArchiveRequest) bool { func allComplete(inFlight []*ArchiveRequest) bool {
@ -79,6 +75,15 @@ func releaseOneEntry(t *testing.T, inFlight []*ArchiveRequest) {
func TestArchive_Basic(t *testing.T) { func TestArchive_Basic(t *testing.T) {
assert.NoError(t, models.PrepareTestDatabase()) 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") ctx := test.MockContext(t, "user27/repo49")
firstCommit, secondCommit := "51f84af23134", "aacbdfe9e1c4" firstCommit, secondCommit := "51f84af23134", "aacbdfe9e1c4"