fix test race in schedule mock (#10309)

This fixes the races that are occurring on tests
([example](https://github.com/fleetdm/fleet/actions/runs/4339799935))
This commit is contained in:
Roberto Dip 2023-03-06 12:24:40 -03:00 committed by GitHub
parent b8fa08b53c
commit aa7466b819
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -506,7 +506,7 @@ func TestTriggerReleaseLock(t *testing.T) {
require.Equal(t, seedStats, statsByType[fleet.CronStatsTypeScheduled])
}
require.True(t, locker.expiresAt.Before(time.Now()))
require.True(t, locker.GetExpiration().Before(time.Now()))
}
func TestMultipleScheduleInstancesConfigChangesDS(t *testing.T) {

View File

@ -99,6 +99,13 @@ func (ml *MockLock) GetLockCount() int {
return ml.LockCount
}
func (ml *MockLock) GetExpiration() time.Time {
ml.mu.Lock()
defer ml.mu.Unlock()
return ml.expiresAt
}
func (ml *MockLock) AddChannels(t *testing.T, chanNames ...string) error {
ml.mu.Lock()
defer ml.mu.Unlock()