You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2023/06/16 09:43:32 UTC
[plc4x] 01/02: test(plc4go/cbus): fix potential shutdown race
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 0d14ba50aa1a29914a922fb4a3044acdd466d05b
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Fri Jun 16 10:23:40 2023 +0200
test(plc4go/cbus): fix potential shutdown race
---
plc4go/internal/cbus/Connection_test.go | 4 ++++
plc4go/spi/default/DefaultCodec.go | 5 +++--
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/plc4go/internal/cbus/Connection_test.go b/plc4go/internal/cbus/Connection_test.go
index a3ed268adc..121d04be55 100644
--- a/plc4go/internal/cbus/Connection_test.go
+++ b/plc4go/internal/cbus/Connection_test.go
@@ -1849,6 +1849,10 @@ func TestConnection_startSubscriptionHandler(t *testing.T) {
tt.manipulator(t, c)
}
c.startSubscriptionHandler()
+ // To shut down properly we always do that
+ time.Sleep(20 * time.Millisecond)
+ c.SetConnected(false)
+ c.handlerWaitGroup.Wait()
})
}
}
diff --git a/plc4go/spi/default/DefaultCodec.go b/plc4go/spi/default/DefaultCodec.go
index 194e599108..e365c5b095 100644
--- a/plc4go/spi/default/DefaultCodec.go
+++ b/plc4go/spi/default/DefaultCodec.go
@@ -168,7 +168,7 @@ func (m *defaultCodec) ConnectWithContext(ctx context.Context) error {
if m.running.Load() {
return errors.New("already running")
}
- m.log.Trace().Msg("Connecting")
+ m.log.Trace().Msg("connecting")
if !m.transportInstance.IsConnected() {
if err := m.transportInstance.ConnectWithContext(ctx); err != nil {
return err
@@ -181,6 +181,7 @@ func (m *defaultCodec) ConnectWithContext(ctx context.Context) error {
m.activeWorker.Add(1)
go m.Work(m.DefaultCodecRequirements)
m.running.Store(true)
+ m.log.Trace().Msg("connected")
return nil
}
@@ -199,7 +200,7 @@ func (m *defaultCodec) Disconnect() error {
}
m.log.Trace().Msg("Waiting for worker to shutdown")
m.activeWorker.Wait()
- m.log.Trace().Msg("Done disconnecting")
+ m.log.Trace().Msg("disconnected")
return nil
}