Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(421)

Side by Side Diff: common/errors/multierror_test.go

Issue 1284323002: Make LazyMultiError only constructable via function (Closed) Base URL: https://github.com/luci/luci-go.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« common/errors/multierror.go ('K') | « common/errors/multierror.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package errors 5 package errors
6 6
7 import ( 7 import (
8 "errors" 8 "errors"
9 "sync" 9 "sync"
10 "testing" 10 "testing"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 Convey("Fix passes through", t, func() { 58 Convey("Fix passes through", t, func() {
59 e := errors.New("unique") 59 e := errors.New("unique")
60 So(Fix(e), ShouldEqual, e) 60 So(Fix(e), ShouldEqual, e)
61 }) 61 })
62 } 62 }
63 63
64 func TestLazyMultiError(t *testing.T) { 64 func TestLazyMultiError(t *testing.T) {
65 t.Parallel() 65 t.Parallel()
66 66
67 Convey("Test LazyMultiError", t, func() { 67 Convey("Test LazyMultiError", t, func() {
68 » » lme := LazyMultiError{Size: 10} 68 » » lme := NewLazyMultiError(10)
69 So(lme.Get(), ShouldEqual, nil) 69 So(lme.Get(), ShouldEqual, nil)
70 70
71 e := errors.New("sup") 71 e := errors.New("sup")
72 lme.Assign(6, e) 72 lme.Assign(6, e)
73 So(lme.Get(), ShouldResemble, 73 So(lme.Get(), ShouldResemble,
74 MultiError{nil, nil, nil, nil, nil, nil, e, nil, nil, ni l}) 74 MultiError{nil, nil, nil, nil, nil, nil, e, nil, nil, ni l})
75 75
76 lme.Assign(2, e) 76 lme.Assign(2, e)
77 So(lme.Get(), ShouldResemble, 77 So(lme.Get(), ShouldResemble,
78 MultiError{nil, nil, e, nil, nil, nil, e, nil, nil, nil} ) 78 MultiError{nil, nil, e, nil, nil, nil, e, nil, nil, nil} )
79 79
80 So(func() { lme.Assign(20, e) }, ShouldPanic) 80 So(func() { lme.Assign(20, e) }, ShouldPanic)
81 81
82 Convey("Try to freak out the race detector", func() { 82 Convey("Try to freak out the race detector", func() {
83 » » » lme := LazyMultiError{Size: 64} 83 » » » lme := NewLazyMultiError(64)
84 Convey("all nils", func() { 84 Convey("all nils", func() {
85 wg := sync.WaitGroup{} 85 wg := sync.WaitGroup{}
86 for i := 0; i < 64; i++ { 86 for i := 0; i < 64; i++ {
87 wg.Add(1) 87 wg.Add(1)
88 go func(i int) { 88 go func(i int) {
89 lme.Assign(i, nil) 89 lme.Assign(i, nil)
90 wg.Done() 90 wg.Done()
91 }(i) 91 }(i)
92 } 92 }
93 wg.Wait() 93 wg.Wait()
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 wg.Wait() 129 wg.Wait()
130 me := make(MultiError, 64) 130 me := make(MultiError, 64)
131 for i := range me { 131 for i := range me {
132 me[i] = wow 132 me[i] = wow
133 } 133 }
134 So(lme.Get(), ShouldResemble, me) 134 So(lme.Get(), ShouldResemble, me)
135 }) 135 })
136 }) 136 })
137 }) 137 })
138 } 138 }
OLDNEW
« common/errors/multierror.go ('K') | « common/errors/multierror.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698