| 1 |
// These tests verify the test running logic. |
| 2 |
|
| 3 |
package check_test |
| 4 |
|
| 5 |
import ( |
| 6 |
"time" |
| 7 |
|
| 8 |
. "github.com/pingcap/check" |
| 9 |
) |
| 10 |
|
| 11 |
var benchmarkS = Suite(&BenchmarkS{}) |
| 12 |
|
| 13 |
type BenchmarkS struct{} |
| 14 |
|
| 15 |
func (s *BenchmarkS) TestCountSuite(c *C) { |
| 16 |
suitesRun += 1 |
| 17 |
} |
| 18 |
|
| 19 |
func (s *BenchmarkS) TestBasicTestTiming(c *C) { |
| 20 |
helper := FixtureHelper{sleepOn: "Test1", sleep: 1000000 * time.Nanosecond} |
| 21 |
output := String{} |
| 22 |
runConf := RunConf{Output: &output, Verbose: true} |
| 23 |
Run(&helper, &runConf) |
| 24 |
|
| 25 |
expected := "PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Test1\t0\\.001s\n" + |
| 26 |
"PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Test2\t0\\.000s\n" |
| 27 |
c.Assert(output.value, Matches, expected) |
| 28 |
} |
| 29 |
|
| 30 |
func (s *BenchmarkS) TestStreamTestTiming(c *C) { |
| 31 |
helper := FixtureHelper{sleepOn: "SetUpSuite", sleep: 1000000 * time.Nanosecond} |
| 32 |
output := String{} |
| 33 |
runConf := RunConf{Output: &output, Stream: true} |
| 34 |
Run(&helper, &runConf) |
| 35 |
|
| 36 |
expected := "(?s).*\nPASS: check_test\\.go:[0-9]+: FixtureHelper\\.SetUpSuite\t *0\\.001s\n.*" |
| 37 |
c.Assert(output.value, Matches, expected) |
| 38 |
} |
| 39 |
|
| 40 |
func (s *BenchmarkS) TestBenchmark(c *C) { |
| 41 |
helper := FixtureHelper{sleep: 100000} |
| 42 |
output := String{} |
| 43 |
runConf := RunConf{ |
| 44 |
Output: &output, |
| 45 |
Benchmark: true, |
| 46 |
BenchmarkTime: 10000000, |
| 47 |
Filter: "Benchmark1", |
| 48 |
} |
| 49 |
Run(&helper, &runConf) |
| 50 |
c.Check(helper.calls[0], Equals, "SetUpSuite") |
| 51 |
c.Check(helper.calls[1], Equals, "SetUpTest") |
| 52 |
c.Check(helper.calls[2], Equals, "Benchmark1") |
| 53 |
c.Check(helper.calls[3], Equals, "TearDownTest") |
| 54 |
c.Check(helper.calls[4], Equals, "SetUpTest") |
| 55 |
c.Check(helper.calls[5], Equals, "Benchmark1") |
| 56 |
c.Check(helper.calls[6], Equals, "TearDownTest") |
| 57 |
// ... and more. |
| 58 |
|
| •59 |
// Relaxed regex to accommodate different machine speeds |
| 60 |
expected := "PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Benchmark1\t *\\d+\t *\\d+ ns/op\n" |
| 61 |
c.Assert(output.value, Matches, expected) |
| 62 |
} |
| 63 |
|
| 64 |
func (s *BenchmarkS) TestBenchmarkBytes(c *C) { |
| 65 |
helper := FixtureHelper{sleep: 100000} |
| 66 |
output := String{} |
| 67 |
runConf := RunConf{ |
| 68 |
Output: &output, |
| 69 |
Benchmark: true, |
| 70 |
BenchmarkTime: 10000000, |
| 71 |
Filter: "Benchmark2", |
| 72 |
} |
| 73 |
Run(&helper, &runConf) |
| 74 |
|
| •75 |
// Relaxed regex to accommodate different machine speeds and throughput |
| 76 |
expected := "PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Benchmark2\t *\\d+\t *\\d+ ns/op\t *[0-9]+\\.[0-9]+ MB/s\n" |
| 77 |
c.Assert(output.value, Matches, expected) |
| 78 |
} |
| 79 |
|
| 80 |
func (s *BenchmarkS) TestBenchmarkMem(c *C) { |
| 81 |
helper := FixtureHelper{sleep: 100000} |
| 82 |
output := String{} |
| 83 |
runConf := RunConf{ |
| 84 |
Output: &output, |
| 85 |
Benchmark: true, |
| 86 |
BenchmarkMem: true, |
| 87 |
BenchmarkTime: 10000000, |
| 88 |
Filter: "Benchmark3", |
| 89 |
} |
| 90 |
Run(&helper, &runConf) |
| 91 |
|
| •92 |
// Relaxed regex to accommodate different machine speeds |
| 93 |
expected := "PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Benchmark3\t *\\d+\t *\\d+ ns/op\t *[0-9]+ B/op\t *[0-9]+ allocs/op\n" |
| 94 |
c.Assert(output.value, Matches, expected) |
| 95 |
} |