fix(skills): stop racing background install in retry tests
InstallSkill returns after starting a goroutine, so asserting status==installing immediately is flaky on fast CI. Wait for the fixture run to finish instead; a skip would never write a new snapshot.main
parent
0ad08d41be
commit
fc7f37da9b
|
|
@ -798,6 +798,25 @@ func TestInstallSkillSkipsWhenReadyWithTheSameArchive(t *testing.T) {
|
|||
"a skip must still attach the install to the workspace catalog")
|
||||
}
|
||||
|
||||
// waitBackgroundInstallReady waits until the InstallSkill goroutine has
|
||||
// finished the fixture run. InstallSkill only queues the work, so reading
|
||||
// Status immediately after it returns races: the mock often lands on ready
|
||||
// before the test process runs the next line. A skip never writes a new
|
||||
// snapshot, so this is also the proof that a retry actually ran.
|
||||
func waitBackgroundInstallReady(t *testing.T, fx *installFixture, msgAndArgs ...any) *types.TenantSkillEntity {
|
||||
t.Helper()
|
||||
var skill *types.TenantSkillEntity
|
||||
require.Eventually(t, func() bool {
|
||||
got, err := fx.skillRepo.GetSkill(context.Background(), 7, "cfg-1", "sk-1")
|
||||
if err != nil || got == nil {
|
||||
return false
|
||||
}
|
||||
skill = got
|
||||
return got.Status == types.SkillStatusReady && got.InstalledSnapshotID != ""
|
||||
}, 2*time.Second, 5*time.Millisecond, msgAndArgs...)
|
||||
return skill
|
||||
}
|
||||
|
||||
func TestInstallSkillRetriesAFailedSkillWithTheSameArchive(t *testing.T) {
|
||||
fx := newInstallFixture(t)
|
||||
archive := zipBundle(t, map[string]string{
|
||||
|
|
@ -816,10 +835,9 @@ func TestInstallSkillRetriesAFailedSkillWithTheSameArchive(t *testing.T) {
|
|||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "sk-1", id)
|
||||
skill, getErr := fx.skillRepo.GetSkill(context.Background(), 7, "cfg-1", "sk-1")
|
||||
require.NoError(t, getErr)
|
||||
require.Equal(t, types.SkillStatusInstalling, skill.Status,
|
||||
skill := waitBackgroundInstallReady(t, fx,
|
||||
"a failed skill is a retry even when the archive digest is unchanged")
|
||||
require.Empty(t, skill.Error)
|
||||
}
|
||||
|
||||
// Most failed installs fail for a reason the archive cannot fix, so the retry
|
||||
|
|
@ -912,9 +930,7 @@ func TestInstallSkillReinstallsWhenTheLiveImageNoLongerCarriesTheSkill(t *testin
|
|||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "sk-1", id)
|
||||
skill, getErr := fx.skillRepo.GetSkill(context.Background(), 7, "cfg-1", "sk-1")
|
||||
require.NoError(t, getErr)
|
||||
require.Equal(t, types.SkillStatusInstalling, skill.Status,
|
||||
waitBackgroundInstallReady(t, fx,
|
||||
"a ready row whose files left the image is a repair, not a skip")
|
||||
}
|
||||
|
||||
|
|
@ -990,13 +1006,10 @@ func TestInstallSkillRetriesAStaleInFlightInstallOfTheSameArchive(t *testing.T)
|
|||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "sk-1", id)
|
||||
skill, getErr := fx.skillRepo.GetSkill(context.Background(), 7, "cfg-1", "sk-1")
|
||||
require.NoError(t, getErr)
|
||||
require.Equal(t, types.SkillStatusInstalling, skill.Status)
|
||||
require.NotNil(t, skill.InstallingSince)
|
||||
require.Equal(t, fx.now(), *skill.InstallingSince,
|
||||
skill := waitBackgroundInstallReady(t, fx,
|
||||
"a dead in-flight row must be allowed to start a new run, not wait for the reaper")
|
||||
require.Empty(t, skill.Error)
|
||||
require.Nil(t, skill.InstallingSince)
|
||||
}
|
||||
|
||||
// The ledger records which skill an install snapshotted, not which archive, so
|
||||
|
|
@ -1137,9 +1150,7 @@ func TestInstallSkillDoesNotSkipARemovalOfTheSameArchive(t *testing.T) {
|
|||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "sk-1", id)
|
||||
skill, getErr := fx.skillRepo.GetSkill(context.Background(), 7, "cfg-1", "sk-1")
|
||||
require.NoError(t, getErr)
|
||||
require.Equal(t, types.SkillStatusInstalling, skill.Status,
|
||||
waitBackgroundInstallReady(t, fx,
|
||||
"re-uploading during a removal is how the upload cancels it")
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue