|
@@ -6,6 +6,7 @@ import (
|
|
|
"io"
|
|
|
"net"
|
|
|
"strconv"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
|
|
@@ -33,6 +34,11 @@ type MockBroker struct {
|
|
|
expectations chan encoder
|
|
|
listener net.Listener
|
|
|
t TestState
|
|
|
+ latency time.Duration
|
|
|
+}
|
|
|
+
|
|
|
+func (b *MockBroker) SetLatency(latency time.Duration) {
|
|
|
+ b.latency = latency
|
|
|
}
|
|
|
|
|
|
func (b *MockBroker) BrokerID() int32 {
|
|
@@ -80,6 +86,10 @@ func (b *MockBroker) serverLoop() (ok bool) {
|
|
|
return b.serverError(err, conn)
|
|
|
}
|
|
|
|
|
|
+ if b.latency > 0 {
|
|
|
+ time.Sleep(b.latency)
|
|
|
+ }
|
|
|
+
|
|
|
response, err := encode(expectation)
|
|
|
if err != nil {
|
|
|
return false
|