Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the possibility to introduce latency to the mock broker #295

Merged
merged 1 commit into from Feb 23, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions mockbroker.go
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"net"
"strconv"
"time"
)

// TestState is a generic interface for a test state, implemented e.g. by testing.T
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down