[flaky] Fix flaky tests caused by port binding#149
Conversation
|
|
||
| var err error | ||
| var listener net.Listener | ||
| if ctx == nil || c.Endpoint.Port == 0 { |
There was a problem hiding this comment.
It is not intuitive that when the ctx is nil, retry till successful binding is not executed. I notice all callers to pass the ctx in the current code. Do we need this check?
There was a problem hiding this comment.
Leftover code. Good catch!
| // It stores the listener object internally to be reused on subsequent calls to Listener(). | ||
| func (c *ServerConfig) PreAllocateListener() (net.Listener, error) { | ||
| listener, err := c.Listener() | ||
| listener, err := c.Listener(context.Background()) |
There was a problem hiding this comment.
Do we plan to pass the ctx as an argument to this PreallocateListener() in the future?
There was a problem hiding this comment.
No. PreallocateListener should only be used with port=0. If such attempt fails, there is no reason to retry.
| t.Log("One server down") | ||
| servers[2].Servers[0].Stop() | ||
| waitUntilGrpcServerIsDown(ctx, t, &servers[2].Configs[0].Endpoint) | ||
| listener1 := holdPort(ctx, t, servers[2].Configs[0]) |
There was a problem hiding this comment.
Earlier, we only checked whether the server was down or not. Now, we create another fake listener and explicitly close it. Can you please explain the reason as I might be missing the core issue?
There was a problem hiding this comment.
I added the following comment to holdPort to clarify its use case
// holdPort attempts to bind to the specified server port and holds it until the listener is closed.
// It serves two purposes:
// 1. A successful bind indicates the port is free, meaning the server previously using it is down.
// 2. It prevents other tests from binding to the same port, ensuring this test correctly detects the server as
// unavailable.Signed-off-by: Liran Funaro <liran.funaro@gmail.com>
Signed-off-by: Liran Funaro <liran.funaro@gmail.com>
d6a3392 to
4b0e58e
Compare
#### Type of change - Test update #### Description - [ServerConfig] Add retry mechanism when binding to a predefined port (`c.Listener()`). - [TestBroadcastDeliver] Use the above retry mechanism to ensure the port is not used by other tests. #### Related issues - resolves hyperledger#109 - resolves hyperledger#137 --------- Signed-off-by: Liran Funaro <liran.funaro@gmail.com>
#### Type of change - Test update #### Description - [ServerConfig] Add retry mechanism when binding to a predefined port (`c.Listener()`). - [TestBroadcastDeliver] Use the above retry mechanism to ensure the port is not used by other tests. #### Related issues - resolves hyperledger#109 - resolves hyperledger#137 --------- Signed-off-by: Liran Funaro <liran.funaro@gmail.com> Signed-off-by: Effi-S <effi.szt@gmail.com>
#### Type of change - Test update #### Description - [ServerConfig] Add retry mechanism when binding to a predefined port (`c.Listener()`). - [TestBroadcastDeliver] Use the above retry mechanism to ensure the port is not used by other tests. #### Related issues - resolves hyperledger#109 - resolves hyperledger#137 --------- Signed-off-by: Liran Funaro <liran.funaro@gmail.com> Signed-off-by: Effi-S <effi.szt@gmail.com>
Type of change
Description
c.Listener()).Related issues