Manager: add 'canary' test to all timeout checker tests
The canary test asserts that certain constants still have the expected value. Lowering those constants is good for testing the timeout stuff with the actual Flamenco Manager + Worker (without having to wait 5 minutes for it to kick in), but it's too easy to accidentally run the unit tests and get cryptic errors about everything failing horribly and miserably when you leave those constants low.
This commit is contained in:
parent
5dac3c2dc0
commit
1de1e3a9a5
@ -19,6 +19,8 @@ import (
|
|||||||
const taskTimeout = 20 * time.Minute
|
const taskTimeout = 20 * time.Minute
|
||||||
|
|
||||||
func TestTimeoutCheckerTiming(t *testing.T) {
|
func TestTimeoutCheckerTiming(t *testing.T) {
|
||||||
|
canaryTest(t)
|
||||||
|
|
||||||
ttc, finish, mocks := timeoutCheckerTestFixtures(t)
|
ttc, finish, mocks := timeoutCheckerTestFixtures(t)
|
||||||
defer finish()
|
defer finish()
|
||||||
|
|
||||||
@ -81,12 +83,7 @@ func TestTimeoutCheckerTiming(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTaskTimeout(t *testing.T) {
|
func TestTaskTimeout(t *testing.T) {
|
||||||
// Canary test: if these constants do not have the expected value, the test
|
canaryTest(t)
|
||||||
// will fail rather cryptically.
|
|
||||||
if !assert.Equal(t, 5*time.Minute, timeoutInitialSleep, "timeoutInitialSleep does not have the expected value") ||
|
|
||||||
!assert.Equal(t, 1*time.Minute, timeoutCheckInterval, "timeoutCheckInterval does not have the expected value") {
|
|
||||||
t.FailNow()
|
|
||||||
}
|
|
||||||
|
|
||||||
ttc, finish, mocks := timeoutCheckerTestFixtures(t)
|
ttc, finish, mocks := timeoutCheckerTestFixtures(t)
|
||||||
defer finish()
|
defer finish()
|
||||||
|
@ -6,9 +6,11 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/benbjohnson/clock"
|
"github.com/benbjohnson/clock"
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"git.blender.org/flamenco/internal/manager/timeout_checker/mocks"
|
"git.blender.org/flamenco/internal/manager/timeout_checker/mocks"
|
||||||
)
|
)
|
||||||
@ -72,3 +74,15 @@ func timeoutCheckerTestFixtures(t *testing.T) (*TimeoutChecker, func(), *Timeout
|
|||||||
)
|
)
|
||||||
return sm, finish, mocks
|
return sm, finish, mocks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// canaryTest will abort the current test if timing constants do not have the
|
||||||
|
// expected value. Unit tests will fail rather cryptically by themselves if the
|
||||||
|
// timing of the timeout checker is not what is expected.
|
||||||
|
func canaryTest(t *testing.T) {
|
||||||
|
if assert.Equal(t, 5*time.Minute, timeoutInitialSleep, "timeoutInitialSleep does not have the expected value") &&
|
||||||
|
assert.Equal(t, 1*time.Minute, timeoutCheckInterval, "timeoutCheckInterval does not have the expected value") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t.Fatal("timing-related constants are not as expected by the unit test, preemptively aborting.")
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
@ -15,6 +15,8 @@ import (
|
|||||||
const workerTimeout = 20 * time.Minute
|
const workerTimeout = 20 * time.Minute
|
||||||
|
|
||||||
func TestWorkerTimeout(t *testing.T) {
|
func TestWorkerTimeout(t *testing.T) {
|
||||||
|
canaryTest(t)
|
||||||
|
|
||||||
ttc, finish, mocks := timeoutCheckerTestFixtures(t)
|
ttc, finish, mocks := timeoutCheckerTestFixtures(t)
|
||||||
defer finish()
|
defer finish()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user