diff options
| author | Will Hawkins <[email protected]> | 2023-12-13 19:56:03 -0500 |
|---|---|---|
| committer | Will Hawkins <[email protected]> | 2024-01-04 19:10:37 -0500 |
| commit | f3990f950277c2f61e0e1811b4b8a81fc0219da4 (patch) | |
| tree | 6969e4ac2c4e94e75fe2e0c5581da5c07785dce8 /executor/executor_test.go | |
| parent | 552f01ad73248474553ce471695745db58c862ea (diff) | |
[Feature] Support for testing upload/download in parallel
Use the `--rpm.parallel` to test in parallel mode. The default testing
mode is serial.
Signed-off-by: Will Hawkins <[email protected]>
Diffstat (limited to 'executor/executor_test.go')
| -rw-r--r-- | executor/executor_test.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/executor/executor_test.go b/executor/executor_test.go new file mode 100644 index 0000000..9c3af7e --- /dev/null +++ b/executor/executor_test.go @@ -0,0 +1,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()) + } +} |
