1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-28 23:06:14 -04:00
v2fly/common/signal/exec_test.go

44 lines
875 B
Go
Raw Normal View History

2016-12-29 18:32:20 -05:00
package signal_test
import (
"context"
2016-12-29 18:32:20 -05:00
"errors"
"testing"
2018-04-11 10:52:51 -04:00
"time"
2016-12-29 18:32:20 -05:00
. "v2ray.com/core/common/signal"
2017-10-24 10:15:35 -04:00
. "v2ray.com/ext/assert"
2016-12-29 18:32:20 -05:00
)
2018-04-11 10:52:51 -04:00
func TestExecuteParallel(t *testing.T) {
2017-10-24 10:15:35 -04:00
assert := With(t)
2016-12-29 18:32:20 -05:00
2018-04-11 10:52:51 -04:00
err := ExecuteParallel(context.Background(), func() error {
time.Sleep(time.Millisecond * 200)
return errors.New("test")
}, func() error {
time.Sleep(time.Millisecond * 500)
return errors.New("test2")
})
2016-12-29 18:32:20 -05:00
2017-10-24 10:15:35 -04:00
assert(err.Error(), Equals, "test")
2016-12-29 18:32:20 -05:00
}
2018-04-11 10:52:51 -04:00
func TestExecuteParallelContextCancel(t *testing.T) {
2017-10-24 10:15:35 -04:00
assert := With(t)
2016-12-29 18:32:20 -05:00
2018-04-11 10:52:51 -04:00
ctx, cancel := context.WithCancel(context.Background())
err := ExecuteParallel(ctx, func() error {
time.Sleep(time.Millisecond * 2000)
return errors.New("test")
}, func() error {
time.Sleep(time.Millisecond * 5000)
return errors.New("test2")
}, func() error {
cancel()
return nil
})
assert(err.Error(), HasSubstring, "canceled")
2016-12-29 18:32:20 -05:00
}