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

chore(integration): cleanup on interrupt#283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
johnstcn merged 1 commit intomainfromcj/integration/catch-interrupt
Sep 6, 2024
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletionsintegration/integration_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,10 +7,12 @@ import (
"fmt"
"io"
"os"
"os/signal"
"path/filepath"
"runtime"
"strconv"
"strings"
"sync"
"testing"
"time"

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

t.Logf("created container %s\n", ctr.ID)
t.Cleanup(func() { // Make sure we clean up after ourselves.
// TODO: also have this execute if you Ctrl+C!
var cleanupOnce sync.Once
removeContainer := func() {
t.Logf("stopping container %s\n", ctr.ID)
_ = cli.ContainerRemove(ctx, ctr.ID, container.RemoveOptions{
Force: true,
})
}
// Ensure the container is cleaned up if you press Ctrl+C.
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt)
go func() {
<-sigCh
cleanupOnce.Do(removeContainer)
os.Exit(1)
}()

t.Cleanup(func() { // Make sure we clean up after ourselves.
cleanupOnce.Do(removeContainer)
})

err = cli.ContainerStart(ctx, ctr.ID, container.StartOptions{})
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp