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 2021/04/06 23:37:36 UTC

[plc4x] 02/02: plc4go: fix potential issue with occasional test failures

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 5c051470a8681bbca52befa9cfad8fc033443c06
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed Apr 7 01:37:20 2021 +0200

    plc4go: fix potential issue with occasional test failures
    
    + by using the list of fields from the request we avoid the order problems with golang maps witch leads to occasional test failures as the order can be random
---
 plc4go/internal/plc4go/spi/model/DefaultPlcReadResponse.go         | 7 +++++--
 plc4go/internal/plc4go/spi/model/DefaultPlcSubscriptionResponse.go | 7 +++++--
 plc4go/internal/plc4go/spi/model/DefaultPlcWriteResponse.go        | 7 +++++--
 3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/plc4go/internal/plc4go/spi/model/DefaultPlcReadResponse.go b/plc4go/internal/plc4go/spi/model/DefaultPlcReadResponse.go
index 86dda14..faa37b4 100644
--- a/plc4go/internal/plc4go/spi/model/DefaultPlcReadResponse.go
+++ b/plc4go/internal/plc4go/spi/model/DefaultPlcReadResponse.go
@@ -40,8 +40,11 @@ func NewDefaultPlcReadResponse(request model.PlcReadRequest, responseCodes map[s
 
 func (m DefaultPlcReadResponse) GetFieldNames() []string {
 	var fieldNames []string
-	for fieldName := range m.values {
-		fieldNames = append(fieldNames, fieldName)
+	// We take the field names from the request to keep order as map is not ordered
+	for _, name := range m.request.GetFieldNames() {
+		if _, ok := m.values[name]; ok {
+			fieldNames = append(fieldNames, name)
+		}
 	}
 	return fieldNames
 }
diff --git a/plc4go/internal/plc4go/spi/model/DefaultPlcSubscriptionResponse.go b/plc4go/internal/plc4go/spi/model/DefaultPlcSubscriptionResponse.go
index 03a5770..ef4ee33 100644
--- a/plc4go/internal/plc4go/spi/model/DefaultPlcSubscriptionResponse.go
+++ b/plc4go/internal/plc4go/spi/model/DefaultPlcSubscriptionResponse.go
@@ -41,8 +41,11 @@ func (m DefaultPlcSubscriptionResponse) GetRequest() model.PlcSubscriptionReques
 
 func (m DefaultPlcSubscriptionResponse) GetFieldNames() []string {
 	var fieldNames []string
-	for fieldName := range m.responseCodes {
-		fieldNames = append(fieldNames, fieldName)
+	// We take the field names from the request to keep order as map is not ordered
+	for _, name := range m.request.GetFieldNames() {
+		if _, ok := m.responseCodes[name]; ok {
+			fieldNames = append(fieldNames, name)
+		}
 	}
 	return fieldNames
 }
diff --git a/plc4go/internal/plc4go/spi/model/DefaultPlcWriteResponse.go b/plc4go/internal/plc4go/spi/model/DefaultPlcWriteResponse.go
index 264e831..edeb707 100644
--- a/plc4go/internal/plc4go/spi/model/DefaultPlcWriteResponse.go
+++ b/plc4go/internal/plc4go/spi/model/DefaultPlcWriteResponse.go
@@ -37,8 +37,11 @@ func NewDefaultPlcWriteResponse(request model.PlcWriteRequest, responseCodes map
 
 func (m DefaultPlcWriteResponse) GetFieldNames() []string {
 	var fieldNames []string
-	for fieldName := range m.responseCodes {
-		fieldNames = append(fieldNames, fieldName)
+	// We take the field names from the request to keep order as map is not ordered
+	for _, name := range m.request.GetFieldNames() {
+		if _, ok := m.responseCodes[name]; ok {
+			fieldNames = append(fieldNames, name)
+		}
 	}
 	return fieldNames
 }