[FIXED] Flapping TestMQTTLockedSession (#4604)

A test-only fix.

I can not reproduce the flapping behavior, but did see a race during
debugging suggesting that the CONNACK is delivered to the test before
`mqttProcessConnect` finishes and releases the record.
This commit is contained in:
Derek Collison
2023-09-28 13:16:46 -07:00
committed by GitHub

View File

@@ -4654,7 +4654,8 @@ func TestMQTTLockedSession(t *testing.T) {
s := testMQTTRunServer(t, o)
defer testMQTTShutdownServer(s)
ci := &mqttConnInfo{clientID: "sub", cleanSess: false}
subClientID := "sub"
ci := &mqttConnInfo{clientID: subClientID, cleanSess: false}
c, r := testMQTTConnect(t, ci, o.MQTT.Host, o.MQTT.Port)
defer c.Close()
testMQTTCheckConnAck(t, r, mqttConnAckRCConnectionAccepted, false)
@@ -4667,8 +4668,20 @@ func TestMQTTLockedSession(t *testing.T) {
t.Fatalf("account session manager not found")
}
// It is possible, however unlikely, to have received CONNACK while
// mqttProcessConnect is still running, and the session remains locked. Wait
// for it to finish.
checkFor(t, 250*time.Millisecond, 10*time.Millisecond, func() error {
asm.mu.RLock()
defer asm.mu.RUnlock()
if _, stillLocked := asm.sessLocked[subClientID]; stillLocked {
return fmt.Errorf("session still locked")
}
return nil
})
// Get the session for "sub"
cli := testMQTTGetClient(t, s, "sub")
cli := testMQTTGetClient(t, s, subClientID)
sess := cli.mqtt.sess
// Pretend that the session above is locked.