-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathany_err_test.go
43 lines (37 loc) · 930 Bytes
/
any_err_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
package ctxroutines
import (
"errors"
"testing"
)
func TestAnyErrOK(t *testing.T) {
ch1 := make(chan struct{})
ch2 := make(chan struct{})
f1 := NoCancelRunner(func() error { close(ch1); return nil })
f2 := NoCancelRunner(func() error { close(ch2); return nil })
err := AnyErr(f1, f2).Run()
if err != nil {
t.Fatal("unexpected error:", err)
}
select {
case <-ch1:
default:
t.Fatal("f1 not stopped")
}
select {
case <-ch2:
default:
t.Fatal("f2 not stopped")
}
}
func TestAnyErr(t *testing.T) {
e := errors.New("")
f1 := NoCancelRunner(func() error { return e })
f2 := NoCancelRunner(func() error { return nil })
err := AnyErr(f1, f2).Run()
if err != e {
t.Fatal("unexpected error:", err)
}
}