fix(go): decouple mqtt message publishing from shutdown context
This commit is contained in:
@@ -69,6 +69,45 @@ func TestMQTTClientHandleBadPayloadPublishesOnlyRaw(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMQTTClientUsesUncancelledMessageContextForReceivedMessage(t *testing.T) {
|
||||
parent, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
resolver := &contextCheckingResolver{}
|
||||
sink := &contextCheckingSink{}
|
||||
client, err := NewMQTTClient(MQTTClientConfig{
|
||||
EndpointName: "endpoint-a",
|
||||
Broker: "tcp://127.0.0.1:1883",
|
||||
ClientID: "test-client",
|
||||
Topics: []string{"/ytforward/shln/+"},
|
||||
Sink: sink,
|
||||
Resolver: resolver,
|
||||
Logger: slog.New(slog.NewTextHandler(testWriter{t: t}, nil)),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("NewMQTTClient() error = %v", err)
|
||||
}
|
||||
|
||||
client.handleMessage(parent, "/ytforward/shln/dev1", []byte(`{
|
||||
"device":"LTEST000000000001",
|
||||
"time":"20260413100000",
|
||||
"data":{"METER_SPEED":52.3,"TOTAL_MILEAGE":123456.7}
|
||||
}`))
|
||||
|
||||
if resolver.ctxErr != nil {
|
||||
t.Fatalf("resolver saw cancelled context: %v", resolver.ctxErr)
|
||||
}
|
||||
if sink.rawCtxErr != nil {
|
||||
t.Fatalf("raw publish saw cancelled context: %v", sink.rawCtxErr)
|
||||
}
|
||||
if sink.unifiedCtxErr != nil {
|
||||
t.Fatalf("unified publish saw cancelled context: %v", sink.unifiedCtxErr)
|
||||
}
|
||||
if sink.rawCount != 1 || sink.unifiedCount != 1 {
|
||||
t.Fatalf("raw=%d unified=%d", sink.rawCount, sink.unifiedCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMQTTClientBuildOptionsLoadsTLSCertificates(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
caPath, certPath, keyPath := writeTestTLSMaterial(t, dir)
|
||||
|
||||
Reference in New Issue
Block a user