summaryrefslogtreecommitdiff
path: root/src/sync
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2014-09-16 14:22:33 -0700
committerJosh Bleecher Snyder <josharian@gmail.com>2014-09-16 14:22:33 -0700
commitb8bda7526a56e959b2aade18c392fb6e4d39e7b5 (patch)
tree297c6739143a168f2ce8160b0e5b728b28e0a388 /src/sync
parent000836fa382e6a9806a176c6021f9b9c56277c8c (diff)
downloadgo-b8bda7526a56e959b2aade18c392fb6e4d39e7b5.tar.gz
sync: simplify TestOncePanic
Follow-up to CL 137350043. LGTM=r R=r CC=golang-codereviews https://codereview.appspot.com/141620043
Diffstat (limited to 'src/sync')
-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")
})
}