Skip to content

Commit 0c83a2b

Browse files
committed
Sandbox termination tests
1 parent fc3aaa9 commit 0c83a2b

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

modal-go/test/sandbox_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,3 +1034,45 @@ func TestSandboxExecOutputTimeout(t *testing.T) {
10341034
g.Expect(elapsed).To(gomega.BeNumerically(">", 1*time.Second))
10351035
g.Expect(elapsed).To(gomega.BeNumerically("<", 15*time.Second))
10361036
}
1037+
1038+
func TestSandboxDoubleTerminate(t *testing.T) {
1039+
t.Parallel()
1040+
g := gomega.NewWithT(t)
1041+
ctx := context.Background()
1042+
tc := newTestClient(t)
1043+
1044+
app, err := tc.Apps.FromName(ctx, "libmodal-test", &modal.AppFromNameParams{CreateIfMissing: true})
1045+
g.Expect(err).ToNot(gomega.HaveOccurred())
1046+
1047+
image := tc.Images.FromRegistry("alpine:3.21", nil)
1048+
1049+
sb, err := tc.Sandboxes.Create(ctx, app, image, nil)
1050+
g.Expect(err).ToNot(gomega.HaveOccurred())
1051+
1052+
err = sb.Terminate(ctx)
1053+
g.Expect(err).ToNot(gomega.HaveOccurred())
1054+
1055+
err = sb.Terminate(ctx)
1056+
g.Expect(err).ToNot(gomega.HaveOccurred())
1057+
}
1058+
1059+
func TestSandboxExecAfterTerminate(t *testing.T) {
1060+
t.Parallel()
1061+
g := gomega.NewWithT(t)
1062+
ctx := context.Background()
1063+
tc := newTestClient(t)
1064+
1065+
app, err := tc.Apps.FromName(ctx, "libmodal-test", &modal.AppFromNameParams{CreateIfMissing: true})
1066+
g.Expect(err).ToNot(gomega.HaveOccurred())
1067+
1068+
image := tc.Images.FromRegistry("alpine:3.21", nil)
1069+
1070+
sb, err := tc.Sandboxes.Create(ctx, app, image, nil)
1071+
g.Expect(err).ToNot(gomega.HaveOccurred())
1072+
1073+
err = sb.Terminate(ctx)
1074+
g.Expect(err).ToNot(gomega.HaveOccurred())
1075+
1076+
_, err = sb.Exec(ctx, []string{"echo", "hello"}, nil)
1077+
g.Expect(err).To(gomega.HaveOccurred())
1078+
}

modal-js/test/sandbox.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,3 +992,28 @@ test("SandboxExecOutputTimeout", async () => {
992992
expect(elapsed).toBeLessThan(4000);
993993
}
994994
});
995+
996+
test("SandboxDoubleTerminate", async () => {
997+
const app = await tc.apps.fromName("libmodal-test", {
998+
createIfMissing: true,
999+
});
1000+
const image = tc.images.fromRegistry("alpine:3.21");
1001+
1002+
const sb = await tc.sandboxes.create(app, image);
1003+
1004+
await sb.terminate();
1005+
await sb.terminate();
1006+
});
1007+
1008+
test("SandboxExecAfterTerminate", async () => {
1009+
const app = await tc.apps.fromName("libmodal-test", {
1010+
createIfMissing: true,
1011+
});
1012+
const image = tc.images.fromRegistry("alpine:3.21");
1013+
1014+
const sb = await tc.sandboxes.create(app, image);
1015+
1016+
await sb.terminate();
1017+
1018+
await expect(sb.exec(["echo", "hello"])).rejects.toThrow();
1019+
});

0 commit comments

Comments
 (0)