Skip to content

Commit a8e38ce

Browse files
committed
tests: add tests for all tasks alloc restart
1 parent 05ef55e commit a8e38ce

File tree

5 files changed

+609
-8
lines changed

5 files changed

+609
-8
lines changed

client/alloc_endpoint_test.go

+39
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,45 @@ func TestAllocations_Restart(t *testing.T) {
6868
})
6969
}
7070

71+
func TestAllocations_RestartAllTasks(t *testing.T) {
72+
ci.Parallel(t)
73+
74+
require := require.New(t)
75+
client, cleanup := TestClient(t, nil)
76+
defer cleanup()
77+
78+
alloc := mock.LifecycleAlloc()
79+
require.Nil(client.addAlloc(alloc, ""))
80+
81+
// Can't restart all tasks while specifying a task name.
82+
req := &nstructs.AllocRestartRequest{
83+
AllocID: alloc.ID,
84+
AllTasks: true,
85+
TaskName: "web",
86+
}
87+
var resp nstructs.GenericResponse
88+
err := client.ClientRPC("Allocations.Restart", &req, &resp)
89+
require.Error(err)
90+
91+
// Good request.
92+
req = &nstructs.AllocRestartRequest{
93+
AllocID: alloc.ID,
94+
AllTasks: true,
95+
}
96+
97+
testutil.WaitForResult(func() (bool, error) {
98+
var resp2 nstructs.GenericResponse
99+
err := client.ClientRPC("Allocations.Restart", &req, &resp2)
100+
if err != nil && strings.Contains(err.Error(), "not running") {
101+
return false, err
102+
}
103+
104+
return true, nil
105+
}, func(err error) {
106+
t.Fatalf("err: %v", err)
107+
})
108+
}
109+
71110
func TestAllocations_Restart_ACL(t *testing.T) {
72111
ci.Parallel(t)
73112
require := require.New(t)

0 commit comments

Comments
 (0)