mirror of
https://github.com/golang/go
synced 2024-11-16 21:44:52 -07:00
os/signal: remove some arbitrary timeouts in tests
This should fix the test flake found in https://build.golang.org/log/48ffb18e85dda480b7a67e8305dd03ee8337f170. For #58901. Change-Id: I1fcdd713a78e6b7c81e38133ce5f42f7f448a1a3 Reviewed-on: https://go-review.googlesource.com/c/go/+/541115 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com>
This commit is contained in:
parent
291ffcbea6
commit
1b03ec8a25
@ -12,9 +12,10 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var neverReady = make(chan struct{}) // never closed
|
||||||
|
|
||||||
// This example passes a context with a signal to tell a blocking function that
|
// This example passes a context with a signal to tell a blocking function that
|
||||||
// it should abandon its work after a signal is received.
|
// it should abandon its work after a signal is received.
|
||||||
func ExampleNotifyContext() {
|
func ExampleNotifyContext() {
|
||||||
@ -35,8 +36,8 @@ func ExampleNotifyContext() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-time.After(time.Second):
|
case <-neverReady:
|
||||||
fmt.Println("missed signal")
|
fmt.Println("ready")
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
fmt.Println(ctx.Err()) // prints "context canceled"
|
fmt.Println(ctx.Err()) // prints "context canceled"
|
||||||
stop() // stop receiving signal notifications as soon as possible.
|
stop() // stop receiving signal notifications as soon as possible.
|
||||||
|
@ -797,14 +797,10 @@ func TestNotifyContextStop(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stop()
|
stop()
|
||||||
select {
|
<-c.Done()
|
||||||
case <-c.Done():
|
|
||||||
if got := c.Err(); got != context.Canceled {
|
if got := c.Err(); got != context.Canceled {
|
||||||
t.Errorf("c.Err() = %q, want %q", got, context.Canceled)
|
t.Errorf("c.Err() = %q, want %q", got, context.Canceled)
|
||||||
}
|
}
|
||||||
case <-time.After(time.Second):
|
|
||||||
t.Errorf("timed out waiting for context to be done after calling stop")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNotifyContextCancelParent(t *testing.T) {
|
func TestNotifyContextCancelParent(t *testing.T) {
|
||||||
@ -818,14 +814,10 @@ func TestNotifyContextCancelParent(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cancelParent()
|
cancelParent()
|
||||||
select {
|
<-c.Done()
|
||||||
case <-c.Done():
|
|
||||||
if got := c.Err(); got != context.Canceled {
|
if got := c.Err(); got != context.Canceled {
|
||||||
t.Errorf("c.Err() = %q, want %q", got, context.Canceled)
|
t.Errorf("c.Err() = %q, want %q", got, context.Canceled)
|
||||||
}
|
}
|
||||||
case <-time.After(time.Second):
|
|
||||||
t.Errorf("timed out waiting for parent context to be canceled")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNotifyContextPrematureCancelParent(t *testing.T) {
|
func TestNotifyContextPrematureCancelParent(t *testing.T) {
|
||||||
@ -840,14 +832,10 @@ func TestNotifyContextPrematureCancelParent(t *testing.T) {
|
|||||||
t.Errorf("c.String() = %q, want %q", got, want)
|
t.Errorf("c.String() = %q, want %q", got, want)
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
<-c.Done()
|
||||||
case <-c.Done():
|
|
||||||
if got := c.Err(); got != context.Canceled {
|
if got := c.Err(); got != context.Canceled {
|
||||||
t.Errorf("c.Err() = %q, want %q", got, context.Canceled)
|
t.Errorf("c.Err() = %q, want %q", got, context.Canceled)
|
||||||
}
|
}
|
||||||
case <-time.After(time.Second):
|
|
||||||
t.Errorf("timed out waiting for parent context to be canceled")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNotifyContextSimultaneousStop(t *testing.T) {
|
func TestNotifyContextSimultaneousStop(t *testing.T) {
|
||||||
@ -868,14 +856,10 @@ func TestNotifyContextSimultaneousStop(t *testing.T) {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
select {
|
<-c.Done()
|
||||||
case <-c.Done():
|
|
||||||
if got := c.Err(); got != context.Canceled {
|
if got := c.Err(); got != context.Canceled {
|
||||||
t.Errorf("c.Err() = %q, want %q", got, context.Canceled)
|
t.Errorf("c.Err() = %q, want %q", got, context.Canceled)
|
||||||
}
|
}
|
||||||
case <-time.After(time.Second):
|
|
||||||
t.Errorf("expected context to be canceled")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNotifyContextStringer(t *testing.T) {
|
func TestNotifyContextStringer(t *testing.T) {
|
||||||
@ -920,7 +904,6 @@ func TestSignalTrace(t *testing.T) {
|
|||||||
if err := trace.Start(buf); err != nil {
|
if err := trace.Start(buf); err != nil {
|
||||||
t.Fatalf("[%d] failed to start tracing: %v", i, err)
|
t.Fatalf("[%d] failed to start tracing: %v", i, err)
|
||||||
}
|
}
|
||||||
time.After(1 * time.Microsecond)
|
|
||||||
trace.Stop()
|
trace.Stop()
|
||||||
size := buf.Len()
|
size := buf.Len()
|
||||||
if size == 0 {
|
if size == 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user