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

fix: fix TestCloserStack_Timeout to wait for all asyncClosers#19837

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
spikecurtis merged 1 commit intomainfromspike/internal-966-async-closer-race
Sep 16, 2025
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
37 changes: 21 additions & 16 deletionscli/ssh_internal_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -158,7 +158,7 @@ func TestCloserStack_CloseAfterContext(t *testing.T) {
logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug)
uut := newCloserStack(ctx, logger, quartz.NewMock(t))
ac := newAsyncCloser(testCtx, t)
defer ac.complete()
defer ac.unblock()
err := uut.push("async", ac)
require.NoError(t, err)
cancel()
Expand All@@ -178,8 +178,9 @@ func TestCloserStack_CloseAfterContext(t *testing.T) {
t.Fatal("closed before stack was finished")
}

ac.complete()
ac.unblock()
testutil.TryReceive(testCtx, t, closed)
testutil.TryReceive(testCtx, t, ac.done)
}

func TestCloserStack_Timeout(t *testing.T) {
Expand All@@ -198,7 +199,8 @@ func TestCloserStack_Timeout(t *testing.T) {
}
defer func() {
for _, a := range ac {
a.complete()
a.unblock()
testutil.TryReceive(ctx, t, a.done) // ensure we don't race with context cancellation
}
}()

Expand All@@ -215,7 +217,7 @@ func TestCloserStack_Timeout(t *testing.T) {
testutil.TryReceive(ctx, t, ac[1].started)

// middle one finishes
ac[1].complete()
ac[1].unblock()
// bottom starts, but also hangs
testutil.TryReceive(ctx, t, ac[0].started)

Expand DownExpand Up@@ -317,34 +319,37 @@ func (c *fakeCloser) Close() error {
}

type asyncCloser struct {
t *testing.T
ctx context.Context
started chan struct{}
isComplete chan struct{}
comepleteOnce sync.Once
t *testing.T
ctx context.Context
started chan struct{}
done chan struct{}
isUnblocked chan struct{}
unblockOnce sync.Once
}

func (c *asyncCloser) Close() error {
close(c.started)
defer close(c.done)
select {
case <-c.ctx.Done():
c.t.Error("timed out")
return c.ctx.Err()
case <-c.isComplete:
case <-c.isUnblocked:
return nil
}
}

func (c *asyncCloser)complete() {
c.comepleteOnce.Do(func() { close(c.isComplete) })
func (c *asyncCloser)unblock() {
c.unblockOnce.Do(func() { close(c.isUnblocked) })
}

func newAsyncCloser(ctx context.Context, t *testing.T) *asyncCloser {
return &asyncCloser{
t: t,
ctx: ctx,
isComplete: make(chan struct{}),
started: make(chan struct{}),
t: t,
ctx: ctx,
isUnblocked: make(chan struct{}),
started: make(chan struct{}),
done: make(chan struct{}),
}
}

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp