Commit c3efa68d authored by ale's avatar ale
Browse files

Use dynamic threholds in queue_test for robustness

parent 2330227c
......@@ -53,7 +53,7 @@ func rateDo(timeout time.Duration, qps float64, f func()) int {
}
}
func runTest(t *testing.T, tag string, opts *Options, qps float64, expectedCalls int) {
func runTest(t *testing.T, tag string, opts *Options, qps float64) (int, int) {
t.Parallel()
fc := new(fakeClient)
......@@ -75,30 +75,37 @@ func runTest(t *testing.T, tag string, opts *Options, qps float64, expectedCalls
})
time.Sleep(1 * time.Second)
if expectedCalls < 0 {
expectedCalls = n
}
if fc.calls != expectedCalls {
t.Fatalf("%s: wrong number of calls: %d (expected %d)", tag, fc.calls, expectedCalls)
}
if fc.rcvd != n {
t.Fatalf("%s: mismatch between events sent (%d) and received (%d)", tag, n, fc.rcvd)
}
return n, fc.calls
}
func TestSubmitter_LowRate(t *testing.T) {
runTest(t, "qps=10", nil, 1, -1)
sent, calls := runTest(t, "qps=10", nil, 1)
if sent != calls {
t.Fatalf("wrong number of calls: %d (expected %d)", calls, sent)
}
}
func TestSubmitter_HighRate(t *testing.T) {
runTest(t, "qps=1000", &Options{
sent, calls := runTest(t, "qps=1000", &Options{
BurstSize: 2,
}, 1000, 4)
}, 1000)
expected := 2 + sent/1000
if calls != expected {
t.Fatalf("sent=%d calls=%d, expected=%d", sent, calls, expected)
}
}
func TestSubmitter_HighRate_Buffered(t *testing.T) {
runTest(t, "qps=1000/buffered", &Options{
sent, calls := runTest(t, "qps=1000/buffered", &Options{
BurstSize: 2,
MaxStored: 100,
}, 1000, 31)
}, 1000)
expected := 2 + sent/100
if calls != expected {
t.Fatalf("sent=%d calls=%d, expected=%d", sent, calls, expected)
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment