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

Commit0e4d689

Browse files
authored
test: fix cleanup order on provisioner daemon work dir (#9668)
* test: fix cleanup order on provisioner daemon work dir* Reduce the test race condition
1 parent53a985f commit0e4d689

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

‎coderd/coderdtest/coderdtest.go‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,15 +459,20 @@ func NewWithAPI(t testing.TB, options *Options) (*codersdk.Client, io.Closer, *c
459459
funcNewProvisionerDaemon(t testing.TB,coderAPI*coderd.API) io.Closer {
460460
t.Helper()
461461

462+
// t.Cleanup runs in last added, first called order. t.TempDir() will delete
463+
// the directory on cleanup, so we want to make sure the echoServer is closed
464+
// before we go ahead an attempt to delete it's work directory.
465+
// seems t.TempDir() is not safe to call from a different goroutine
466+
workDir:=t.TempDir()
467+
462468
echoClient,echoServer:=provisionersdk.MemTransportPipe()
463469
ctx,cancelFunc:=context.WithCancel(context.Background())
464470
t.Cleanup(func() {
465471
_=echoClient.Close()
466472
_=echoServer.Close()
467473
cancelFunc()
468474
})
469-
// seems t.TempDir() is not safe to call from a different goroutine
470-
workDir:=t.TempDir()
475+
471476
gofunc() {
472477
err:=echo.Serve(ctx,&provisionersdk.ServeOptions{
473478
Listener:echoServer,

‎provisionersdk/session.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,15 @@ func (s *Session) extractArchive() error {
230230
ifmode==0 {
231231
mode=0o600
232232
}
233+
234+
// Always check for context cancellation before reading the next header.
235+
// This is mainly important for unit tests, since a canceled context means
236+
// the underlying directory is going to be deleted. There still exists
237+
// the small race condition that the context is cancelled after this, and
238+
// before the disk write.
239+
ifctx.Err()!=nil {
240+
returnxerrors.Errorf("context canceled: %w",ctx.Err())
241+
}
233242
switchheader.Typeflag {
234243
casetar.TypeDir:
235244
err=os.MkdirAll(headerPath,mode)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp