Skip to content

Commit 8a804ef

Browse files
committed
Add test
1 parent a594db3 commit 8a804ef

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package sandboxes
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
"testing"
7+
"time"
8+
9+
"github.com/stretchr/testify/require"
10+
"golang.org/x/sync/errgroup"
11+
12+
"github.com/e2b-dev/infra/tests/integration/internal/api"
13+
"github.com/e2b-dev/infra/tests/integration/internal/setup"
14+
"github.com/e2b-dev/infra/tests/integration/internal/utils"
15+
)
16+
17+
func TestSandboxSetTimeoutPausingSandbox(t *testing.T) {
18+
c := setup.GetAPIClient()
19+
20+
t.Run("test concurrent pauses", func(t *testing.T) {
21+
sbx := utils.SetupSandboxWithCleanup(t, c, utils.WithAutoPause(true))
22+
sbxId := sbx.SandboxID
23+
24+
// Pause the sandbox
25+
wg := errgroup.Group{}
26+
wg.Go(func() error {
27+
pauseResp, err := c.PostSandboxesSandboxIDPauseWithResponse(t.Context(), sbxId, setup.WithAPIKey())
28+
require.NoError(t, err)
29+
require.Equal(t, http.StatusNoContent, pauseResp.StatusCode())
30+
31+
return nil
32+
})
33+
34+
for range 5 {
35+
time.Sleep(200 * time.Millisecond)
36+
wg.Go(func() error {
37+
setTimeoutResp, err := c.PostSandboxesSandboxIDTimeoutWithResponse(t.Context(), sbxId, api.PostSandboxesSandboxIDTimeoutJSONRequestBody{
38+
Timeout: 15,
39+
},
40+
setup.WithAPIKey())
41+
if err != nil {
42+
return err
43+
}
44+
45+
if setTimeoutResp.StatusCode() != http.StatusNotFound {
46+
return fmt.Errorf("unexpected status code: %d", setTimeoutResp.StatusCode())
47+
}
48+
49+
return nil
50+
})
51+
}
52+
53+
err := wg.Wait()
54+
require.NoError(t, err)
55+
})
56+
}

0 commit comments

Comments
 (0)