-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Improve expectation API to allow for testing of more intricate scenarios #298
Conversation
} | ||
|
||
func (b *MockBroker) SetLatency(latency time.Duration) { | ||
b.latency = latency |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can now be set separately for every expectation/response.
func (b *MockBroker) Returns(response encoder) *MockBrokerExpectation { | ||
expectation := &MockBrokerExpectation{response: response} | ||
b.expectations <- expectation | ||
return expectation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This now returns itself so the methods below can be chained.
Technically this is a bit shitty, because we immediately add it to the expectations channel, but allow it to be altered later. I guess this could cause concurrency issues, but because of the synchronous way our tests are set up I don't think this will cause issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blegh, the race detector is on to me. I guess this needs fixing after all. API suggestions?
CI is failing due to kisielk/errcheck#62 |
25d4d2f
to
37d9cb7
Compare
This is failing on Travis, even though this works fine locally:
any ideas? |
I assume this is caused by the mock broker trying to write a response during/after the reader timeout of the client. |
5254546
to
7f9e00a
Compare
Miraculously, it works by adding a parameter on whether to expect errors to the expectation. |
Hmmm, in some cases is the read timeout appears to be triggered before the mock broker has figured out a request is incoming, and so it won't resolve the expectation. Any ideas of making this more robust, compared to simply raising the read timeout value? |
} | ||
|
||
func (b *MockBroker) SetLatency(latency time.Duration) { | ||
b.latency = latency | ||
type MockCluster map[int32]*MockBroker |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just a slice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make sure the index matches the BrokerID. Broker IDs are 1-indexed, while slice indices start at 0.
Make expectation a separate struct instead of just a response. This type can then be used to have callbacks and other properties, so we can simulate concurrency more easily.
7f9e00a
to
1a44810
Compare
8107d90
to
f138ff3
Compare
This will not be merged in its current form - #312 should be fixed first. |
This makes the API for mock broker expectations a bit more powerful.
Before
andAfter
callback around the response.Use these capabilities to add some tests:
NewClient
will return an error if all brokers have high latency.@Shopify/kafka