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/04/12 11:19:58 UTC

[plc4x] 03/04: test(plc4go/cbus): added more tests for subscribers

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 cec9ad2576abd2d07a5c054ef7dae1b24f51ec39
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed Apr 12 11:44:25 2023 +0200

    test(plc4go/cbus): added more tests for subscribers
---
 plc4go/internal/cbus/Connection_test.go | 38 +++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/plc4go/internal/cbus/Connection_test.go b/plc4go/internal/cbus/Connection_test.go
index 339ceedd89..1413aa998a 100644
--- a/plc4go/internal/cbus/Connection_test.go
+++ b/plc4go/internal/cbus/Connection_test.go
@@ -1645,6 +1645,43 @@ func TestConnection_startSubscriptionHandler(t *testing.T) {
 				DefaultConnection: _default.NewDefaultConnection(nil),
 			},
 		},
+		{
+			name: "just start and feed (no subs)",
+			fields: fields{
+				DefaultConnection: func() _default.DefaultConnection {
+					defaultConnection := _default.NewDefaultConnection(nil)
+					defaultConnection.SetConnected(true)
+					return defaultConnection
+				}(),
+				messageCodec: func() *MessageCodec {
+					messageCodec := NewMessageCodec(nil)
+					go func() {
+						messageCodec.monitoredMMIs <- nil
+						messageCodec.monitoredSALs <- nil
+					}()
+					return messageCodec
+				}(),
+			},
+		},
+		{
+			name: "just start and feed",
+			fields: fields{
+				DefaultConnection: func() _default.DefaultConnection {
+					defaultConnection := _default.NewDefaultConnection(nil)
+					defaultConnection.SetConnected(true)
+					return defaultConnection
+				}(),
+				messageCodec: func() *MessageCodec {
+					messageCodec := NewMessageCodec(nil)
+					go func() {
+						messageCodec.monitoredMMIs <- readWriteModel.NewCALReplyShort(0, nil, nil, nil)
+						messageCodec.monitoredSALs <- readWriteModel.NewMonitoredSAL(0, nil)
+					}()
+					return messageCodec
+				}(),
+				subscribers: []*Subscriber{NewSubscriber(nil)},
+			},
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
@@ -1659,6 +1696,7 @@ func TestConnection_startSubscriptionHandler(t *testing.T) {
 				tracer:            tt.fields.tracer,
 			}
 			c.startSubscriptionHandler()
+			time.Sleep(50 * time.Millisecond)
 		})
 	}
 }