mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-12-26 03:55:26 -05:00
simplify task execution
This commit is contained in:
@@ -14,13 +14,14 @@ import (
|
||||
func TestExecuteParallel(t *testing.T) {
|
||||
assert := With(t)
|
||||
|
||||
err := Run(Parallel(func() error {
|
||||
time.Sleep(time.Millisecond * 200)
|
||||
return errors.New("test")
|
||||
}, func() error {
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
return errors.New("test2")
|
||||
}))()
|
||||
err := Run(context.Background(),
|
||||
func() error {
|
||||
time.Sleep(time.Millisecond * 200)
|
||||
return errors.New("test")
|
||||
}, func() error {
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
return errors.New("test2")
|
||||
})
|
||||
|
||||
assert(err.Error(), Equals, "test")
|
||||
}
|
||||
@@ -29,7 +30,7 @@ func TestExecuteParallelContextCancel(t *testing.T) {
|
||||
assert := With(t)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
err := Run(WithContext(ctx), Parallel(func() error {
|
||||
err := Run(ctx, func() error {
|
||||
time.Sleep(time.Millisecond * 2000)
|
||||
return errors.New("test")
|
||||
}, func() error {
|
||||
@@ -38,7 +39,7 @@ func TestExecuteParallelContextCancel(t *testing.T) {
|
||||
}, func() error {
|
||||
cancel()
|
||||
return nil
|
||||
}))()
|
||||
})
|
||||
|
||||
assert(err.Error(), HasSubstring, "canceled")
|
||||
}
|
||||
@@ -48,7 +49,7 @@ func BenchmarkExecuteOne(b *testing.B) {
|
||||
return nil
|
||||
}
|
||||
for i := 0; i < b.N; i++ {
|
||||
common.Must(Run(Parallel(noop))())
|
||||
common.Must(Run(context.Background(), noop))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,17 +58,6 @@ func BenchmarkExecuteTwo(b *testing.B) {
|
||||
return nil
|
||||
}
|
||||
for i := 0; i < b.N; i++ {
|
||||
common.Must(Run(Parallel(noop, noop))())
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkExecuteContext(b *testing.B) {
|
||||
noop := func() error {
|
||||
return nil
|
||||
}
|
||||
background := context.Background()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
common.Must(Run(WithContext(background), Parallel(noop, noop))())
|
||||
common.Must(Run(context.Background(), noop, noop))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user