blob: 9c3af7e086aa46350a8d1f0f3e4419c5babc0d17 (
plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
|
package executor_test
import (
"testing"
"time"
"github.com/network-quality/goresponsiveness/executor"
)
var countToFive = func() {
time.Sleep(5 * time.Second)
}
var countToThree = func() {
time.Sleep(3 * time.Second)
}
var executionUnits = []executor.ExecutionUnit{countToFive, countToThree}
func TestSerial(t *testing.T) {
then := time.Now()
waiter := executor.Execute(executor.Serial, executionUnits)
waiter.Wait()
when := time.Now()
if when.Sub(then) < 7*time.Second {
t.Fatalf("Execution did not happen serially -- the wait was too short: %v", when.Sub(then).Seconds())
}
}
func TestParallel(t *testing.T) {
then := time.Now()
waiter := executor.Execute(executor.Parallel, executionUnits)
waiter.Wait()
when := time.Now()
if when.Sub(then) > 6*time.Second {
t.Fatalf("Execution did not happen in parallel -- the wait was too long: %v", when.Sub(then).Seconds())
}
}
func TestExecutionMethodParallelToString(t *testing.T) {
executionMethod := executor.Parallel
if executionMethod.ToString() != "Parallel" {
t.Fatalf("Incorrect result from ExecutionMethod.ToString; expected Parallel but got %v", executionMethod.ToString())
}
}
func TestExecutionMethodSerialToString(t *testing.T) {
executionMethod := executor.Serial
if executionMethod.ToString() != "Serial" {
t.Fatalf("Incorrect result from ExecutionMethod.ToString; expected Serial but got %v", executionMethod.ToString())
}
}
|