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

[plc4x] branch develop updated (c0727529e1 -> 708fb98772)

This is an automated email from the ASF dual-hosted git repository.

sruehl pushed a change to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git


    from c0727529e1 build(deps): bump golang.org/x/tools from 0.9.3 to 0.10.0 in /plc4go (#998)
     new 0d14ba50aa test(plc4go/cbus): fix potential shutdown race
     new 708fb98772 test(plc4go/cbus): fix race condition with shutdown

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 plc4go/internal/cbus/Connection.go      |  2 ++
 plc4go/internal/cbus/Connection_test.go | 13 ++++++++++++-
 plc4go/spi/default/DefaultCodec.go      |  5 +++--
 3 files changed, 17 insertions(+), 3 deletions(-)


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

Posted by sr...@apache.org.
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()
 		})
 	}
 }


[plc4x] 01/02: test(plc4go/cbus): fix potential shutdown race

Posted by sr...@apache.org.
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
 }