Skip to content

Commit

Permalink
fix(plc4go/connection-pool): Tried hardening a flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdutz committed Jan 20, 2022
1 parent 019018f commit 01bb30a
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions plc4go/internal/plc4go/utils/pool/PlcConnectionPool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,23 +528,32 @@ func TestPlcConnectionPool_SecondConnectionGivenUpWaiting(t1 *testing.T) {
}

// Wait for 20ms to have the connection pool timeout (10ms) the lease as nobody's listening.
time.Sleep(time.Millisecond * 20)
time.Sleep(time.Millisecond * 50)

// This should be quite equal to the serial case as the connections are requested serially.
assert.NotNil(t1, pool.GetTracer(), "Tracer should be available")
traces := pool.GetTracer().GetTraces()
assert.Equal(t1, 6, len(traces), "Unexpected number of trace entries")
// First is needs to create a new container for this connection
assert.Equal(t1, "create new pooled connection", traces[0].Message, "Unexpected message")
// Then it gets a lease for the connection
assert.Equal(t1, "lease", traces[1].Message, "Unexpected message")
// And a second time
assert.Equal(t1, "lease", traces[2].Message, "Unexpected message")
// Now the delay of 100ms is over, and we should see the first success
assert.Equal(t1, "success", traces[3].Message, "Unexpected message")
// Now the first operation is finished, and we should see the second success
assert.Equal(t1, "success", traces[4].Message, "Unexpected message")
assert.Equal(t1, "client given up", traces[5].Message, "Unexpected message")
if assert.Equal(t1, 6, len(traces), "Unexpected number of trace entries") {
// First is needs to create a new container for this connection
assert.Equal(t1, "create new pooled connection", traces[0].Message, "Unexpected message")
// Then it gets a lease for the connection
assert.Equal(t1, "lease", traces[1].Message, "Unexpected message")
// And a second time
assert.Equal(t1, "lease", traces[2].Message, "Unexpected message")
// Now the delay of 100ms is over, and we should see the first success
assert.Equal(t1, "success", traces[3].Message, "Unexpected message")
// Now the first operation is finished, and we should see the second success
assert.Equal(t1, "success", traces[4].Message, "Unexpected message")
assert.Equal(t1, "client given up", traces[5].Message, "Unexpected message")
} else if len(traces) > 0 {
var values string
for _, traceEntry := range traces {
values = values + traceEntry.Operation + "-" + traceEntry.Message + ", "
}
t1.Errorf("Got traces: %s", values)
} else {
t1.Error("No traces")
}
}

func TestPlcConnectionPool_MaximumWaitTimeReached(t1 *testing.T) {
Expand Down

0 comments on commit 01bb30a

Please sign in to comment.