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:33 UTC

[plc4x] 02/02: test(plc4go/cbus): fix race condition with shutdown

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 708fb98772590f9594f2ab49d5c51769bbcf029f
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Fri Jun 16 11:43:19 2023 +0200

    test(plc4go/cbus): fix race condition with shutdown
---
 plc4go/internal/cbus/Connection.go      | 2 ++
 plc4go/internal/cbus/Connection_test.go | 9 ++++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/plc4go/internal/cbus/Connection.go b/plc4go/internal/cbus/Connection.go
index ec7a0b739f..69ac5d4818 100644
--- a/plc4go/internal/cbus/Connection.go
+++ b/plc4go/internal/cbus/Connection.go
@@ -257,6 +257,7 @@ func (c *Connection) startSubscriptionHandler() {
 		salLogger.Debug().Msg("SAL handler started")
 		for c.IsConnected() {
 			for monitoredSal := range c.messageCodec.monitoredSALs {
+				salLogger.Trace().Msgf("got a SAL\n%v", monitoredSal)
 				handled := false
 				for _, subscriber := range c.subscribers {
 					if ok := subscriber.handleMonitoredSAL(monitoredSal); ok {
@@ -284,6 +285,7 @@ func (c *Connection) startSubscriptionHandler() {
 		mmiLogger.Debug().Msg("default MMI started")
 		for c.IsConnected() {
 			for calReply := range c.messageCodec.monitoredMMIs {
+				mmiLogger.Trace().Msgf("got a MMI:\n%s", calReply)
 				handled := false
 				for _, subscriber := range c.subscribers {
 					if ok := subscriber.handleMonitoredMMI(calReply); ok {
diff --git a/plc4go/internal/cbus/Connection_test.go b/plc4go/internal/cbus/Connection_test.go
index 121d04be55..e4c287bd36 100644
--- a/plc4go/internal/cbus/Connection_test.go
+++ b/plc4go/internal/cbus/Connection_test.go
@@ -218,7 +218,10 @@ func TestConnection_ConnectWithContext(t *testing.T) {
 				log:               testutils.ProduceTestingLogger(t),
 			}
 			assert.True(t, tt.wantAsserter(t, c.ConnectWithContext(tt.args.ctx)), "ConnectWithContext(%v)", tt.args.ctx)
-			time.Sleep(200 * time.Millisecond) // TODO: find out what is still running here
+			// To shut down properly we always do that
+			time.Sleep(20 * time.Millisecond)
+			c.SetConnected(false)
+			c.handlerWaitGroup.Wait()
 		})
 	}
 }
@@ -1751,6 +1754,10 @@ func TestConnection_setupConnection(t *testing.T) {
 				log:               testutils.ProduceTestingLogger(t),
 			}
 			c.setupConnection(tt.args.ctx, tt.args.ch)
+			// To shut down properly we always do that
+			time.Sleep(20 * time.Millisecond)
+			c.SetConnected(false)
+			c.handlerWaitGroup.Wait()
 		})
 	}
 }