summaryrefslogtreecommitdiff
path: root/src/sync/once_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/sync/once_test.go')
-rw-r--r--src/sync/once_test.go30
1 files changed, 12 insertions, 18 deletions
diff --git a/src/sync/once_test.go b/src/sync/once_test.go
index 10beefde3..1eec8d18e 100644
--- a/src/sync/once_test.go
+++ b/src/sync/once_test.go
@@ -40,26 +40,20 @@ func TestOnce(t *testing.T) {
}
func TestOncePanic(t *testing.T) {
- once := new(Once)
- for i := 0; i < 2; i++ {
- func() {
- defer func() {
- r := recover()
- if r == nil && i == 0 {
- t.Fatalf("Once.Do() has not panic'ed on first iteration")
- }
- if r != nil && i == 1 {
- t.Fatalf("Once.Do() has panic'ed on second iteration")
- }
- }()
- once.Do(func() {
- panic("failed")
- })
+ var once Once
+ func() {
+ defer func() {
+ if r := recover(); r == nil {
+ t.Fatalf("Once.Do did not panic")
+ }
}()
- }
- once.Do(func() {})
+ once.Do(func() {
+ panic("failed")
+ })
+ }()
+
once.Do(func() {
- t.Fatalf("Once called twice")
+ t.Fatalf("Once.Do called twice")
})
}