MCPcopy
hub / github.com/tailscale/tailscale / TestDeferredErr

Function TestDeferredErr

types/lazy/deferred_test.go:159–202  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

157}
158
159func TestDeferredErr(t *testing.T) {
160 tests := []struct {
161 name string
162 funcs []func() error
163 wantErr error
164 }{
165 {
166 name: "no-funcs",
167 wantErr: nil,
168 },
169 {
170 name: "no-error",
171 funcs: []func() error{func() error { return nil }},
172 wantErr: nil,
173 },
174 {
175 name: "error",
176 funcs: []func() error{
177 func() error { return nil },
178 func() error { return errors.New("bang!") },
179 func() error { return errors.New("unreachable") },
180 },
181 wantErr: errors.New("bang!"),
182 },
183 }
184 for _, tt := range tests {
185 t.Run(tt.name, func(t *testing.T) {
186 var di DeferredInit
187 for _, f := range tt.funcs {
188 di.MustDefer(f)
189 }
190
191 var wg sync.WaitGroup
192 N := 10000
193 for range N {
194 wg.Go(func() {
195 gotErr := di.Do()
196 checkError(t, gotErr, tt.wantErr, false)
197 })
198 }
199 wg.Wait()
200 })
201 }
202}
203
204// TestDeferAfterDo checks all of the following:
205// - Deferring a function before [DeferredInit.Do] is called should always succeed.

Callers

nothing calls this directly

Calls 7

DoMethod · 0.95
MustDeferMethod · 0.80
GoMethod · 0.80
checkErrorFunction · 0.70
RunMethod · 0.65
WaitMethod · 0.65
NewMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…