| 20 | } |
| 21 | |
| 22 | func TestRun(t *testing.T) { |
| 23 | Convey("Given two AsyncFunc functions returning non error", t, func() { |
| 24 | var exec [2]bool |
| 25 | f1 := func(_ context.Context) error { |
| 26 | exec[0] = true |
| 27 | return nil |
| 28 | } |
| 29 | |
| 30 | f2 := func(_ context.Context) error { |
| 31 | exec[1] = true |
| 32 | return nil |
| 33 | } |
| 34 | |
| 35 | Convey("It should be executed properly", func() { |
| 36 | err := async.Run(context.Background(), f1, f2) |
| 37 | So(err, ShouldBeNil) |
| 38 | So(exec[0], ShouldBeTrue) |
| 39 | So(exec[1], ShouldBeTrue) |
| 40 | }) |
| 41 | }) |
| 42 | |
| 43 | Convey("Given two AsyncFunc and one of them returning an error", t, func() { |
| 44 | var errTest = errors.New("test error") |
| 45 | f1 := func(_ context.Context) error { |
| 46 | return errTest |
| 47 | } |
| 48 | |
| 49 | f2 := func(_ context.Context) error { |
| 50 | return nil |
| 51 | } |
| 52 | |
| 53 | Convey("async.Run() should return that error", func() { |
| 54 | err := async.Run(context.Background(), f1, f2) |
| 55 | So(err, ShouldEqual, errTest) |
| 56 | }) |
| 57 | }) |
| 58 | |
| 59 | Convey("Given two AsyncFunc and one of them executing a panic call", t, func() { |
| 60 | f1 := func(_ context.Context) error { |
| 61 | panic(errors.New("test panic")) |
| 62 | } |
| 63 | |
| 64 | f2 := func(_ context.Context) error { |
| 65 | return nil |
| 66 | } |
| 67 | |
| 68 | Convey("async.Run() should return that panic error", func() { |
| 69 | err := async.Run(context.Background(), f1, f2) |
| 70 | So(err, ShouldNotBeNil) |
| 71 | So(err.Error(), ShouldContainSubstring, "async.Run: panic test panic") |
| 72 | }) |
| 73 | }) |
| 74 | |
| 75 | Convey("Given two AsyncFunc and one of them executing a panic call", t, func() { |
| 76 | var mu sync.Mutex |
| 77 | var exec [2]bool |
| 78 | |
| 79 | f1 := func(_ context.Context) error { |