Skip to content

Commit 3856eee

Browse files
committed
allocrunner: add test for missing alloc dir
1 parent fa9ce4d commit 3856eee

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

client/allocrunner/alloc_runner_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,6 +1422,33 @@ func TestAllocRunner_Restore_LifecycleHooks(t *testing.T) {
14221422
tasklifecycle.RequireTaskAllowed(t, ar2.taskCoordinator, ar2.tasks["poststart"].Task())
14231423
}
14241424

1425+
// TestAllocRunner_Restore_MissingAllocDir asserts that Restore() fails when the
1426+
// allocation directory is missing, which can happen if allocation storage is
1427+
// ephemeral (e.g., tmpfs or cloud local SSDs).
1428+
func TestAllocRunner_Restore_MissingAllocDir(t *testing.T) {
1429+
ci.Parallel(t)
1430+
1431+
alloc := mock.Alloc()
1432+
conf, cleanup := testAllocRunnerConfig(t, alloc)
1433+
defer cleanup()
1434+
1435+
arIface, err := NewAllocRunner(conf)
1436+
must.NoError(t, err)
1437+
ar := arIface.(*allocRunner)
1438+
1439+
// Get the allocation directory path before deleting it
1440+
allocDirPath := ar.allocDir.AllocDirPath()
1441+
1442+
// Remove the allocation directory to simulate ephemeral storage being deleted
1443+
err = os.RemoveAll(allocDirPath)
1444+
must.NoError(t, err)
1445+
1446+
// Call Restore() and verify it fails with appropriate error
1447+
err = ar.Restore()
1448+
must.Error(t, err)
1449+
must.ErrorIs(t, err, os.ErrNotExist)
1450+
}
1451+
14251452
func TestAllocRunner_Update_Semantics(t *testing.T) {
14261453
ci.Parallel(t)
14271454
require := require.New(t)

0 commit comments

Comments
 (0)