Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0da135c

Browse files
authored
chore(integration): cleanup on interrupt (#283)
1 parentf69a14d commit0da135c

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

‎integration/integration_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import (
77
"fmt"
88
"io"
99
"os"
10+
"os/signal"
1011
"path/filepath"
1112
"runtime"
1213
"strconv"
1314
"strings"
15+
"sync"
1416
"testing"
1517
"time"
1618

@@ -203,12 +205,24 @@ func setup(ctx context.Context, t *testing.T, name, coderImg, coderVersion strin
203205
require.NoError(t,err,"create test deployment")
204206

205207
t.Logf("created container %s\n",ctr.ID)
206-
t.Cleanup(func() {// Make sure we clean up after ourselves.
207-
// TODO: also have this execute if you Ctrl+C!
208+
varcleanupOnce sync.Once
209+
removeContainer:=func() {
208210
t.Logf("stopping container %s\n",ctr.ID)
209211
_=cli.ContainerRemove(ctx,ctr.ID, container.RemoveOptions{
210212
Force:true,
211213
})
214+
}
215+
// Ensure the container is cleaned up if you press Ctrl+C.
216+
sigCh:=make(chan os.Signal,1)
217+
signal.Notify(sigCh,os.Interrupt)
218+
gofunc() {
219+
<-sigCh
220+
cleanupOnce.Do(removeContainer)
221+
os.Exit(1)
222+
}()
223+
224+
t.Cleanup(func() {// Make sure we clean up after ourselves.
225+
cleanupOnce.Do(removeContainer)
212226
})
213227

214228
err=cli.ContainerStart(ctx,ctr.ID, container.StartOptions{})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp