aboutsummaryrefslogtreecommitdiff
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
commitf1abe0d06bc94399c4abee041624efa36742fc1e (patch)
tree3198379ab137f80ccac185caedad1eff41876d6b /src/sync
parentb22dc6385d66ac2e74afb9a5d503394fc7273d81 (diff)
downloadgo-f1abe0d06bc94399c4abee041624efa36742fc1e.tar.xz
sync: simplify TestOncePanic
Follow-up to CL 137350043. LGTM=r R=r CC=golang-codereviews https://golang.org/cl/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 10beefde35..1eec8d18ea 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")
})
}