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/20 08:01:05 UTC

[plc4x] branch develop updated: feat(plc4go/spi): added remaining options as env to test utils

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


The following commit(s) were added to refs/heads/develop by this push:
     new d993e8c61f feat(plc4go/spi): added remaining options as env to test utils
d993e8c61f is described below

commit d993e8c61f90b0346bbe28b933ffe4ce73a0e7fb
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Tue Jun 20 10:00:54 2023 +0200

    feat(plc4go/spi): added remaining options as env to test utils
---
 plc4go/spi/testutils/TestUtils.go | 42 ++++++++++++++++++++++++++++++---------
 1 file changed, 33 insertions(+), 9 deletions(-)

diff --git a/plc4go/spi/testutils/TestUtils.go b/plc4go/spi/testutils/TestUtils.go
index a11a94f383..71f3d68b6c 100644
--- a/plc4go/spi/testutils/TestUtils.go
+++ b/plc4go/spi/testutils/TestUtils.go
@@ -24,6 +24,7 @@ import (
 	"os"
 	"runtime"
 	"runtime/debug"
+	"strconv"
 	"strings"
 	"testing"
 	"time"
@@ -119,9 +120,13 @@ func TestContext(t *testing.T) context.Context {
 }
 
 var (
-	highLogPrecision     bool
-	traceExecutorWorkers bool
-	passLoggerToModel    bool
+	highLogPrecision                    bool
+	passLoggerToModel                   bool
+	receiveTimeout                      time.Duration
+	traceTransactionManagerWorkers      bool
+	traceTransactionManagerTransactions bool
+	traceDefaultMessageCodecWorker      bool
+	traceExecutorWorkers                bool
 )
 
 func init() {
@@ -129,13 +134,28 @@ func init() {
 	if highLogPrecision {
 		zerolog.TimeFieldFormat = time.RFC3339Nano
 	}
-	traceExecutorWorkers = true
-	if traceExecutorWorkersEnv := os.Getenv("PLC4X_TEST_TRACE_EXECUTOR_WORKERS"); traceExecutorWorkersEnv != "" {
-		traceExecutorWorkers = traceExecutorWorkersEnv == "true"
+	getOrLeaveBool("PLC4X_TEST_PASS_LOGGER_TO_MODEL", &passLoggerToModel)
+	receiveTimeout = 3 * time.Second
+	getOrLeaveDuration("PLC4X_TEST_RECEIVE_TIMEOUT_MS", &receiveTimeout)
+	getOrLeaveBool("PLC4X_TEST_TRACE_TRANSACTION_MANAGER_WORKERS", &traceTransactionManagerWorkers)
+	getOrLeaveBool("PLC4X_TEST_TRACE_TRANSACTION_MANAGER_TRANSACTIONS", &traceTransactionManagerTransactions)
+	getOrLeaveBool("PLC4X_TEST_TRACE_MESSAGE_CODEC_WORKER", &traceDefaultMessageCodecWorker)
+	getOrLeaveBool("PLC4X_TEST_TRACE_EXECUTOR_WORKERS", &traceExecutorWorkers)
+}
+
+func getOrLeaveBool(key string, setting *bool) {
+	if env := os.Getenv(key); env != "" {
+		*setting = strings.EqualFold(env, "true")
 	}
-	passLoggerToModel = true
-	if passLoggerToModelEnv := os.Getenv("PLC4X_TEST_PASS_LOGGER_TO_MODEL"); passLoggerToModelEnv != "" {
-		passLoggerToModel = passLoggerToModelEnv == "true"
+}
+
+func getOrLeaveDuration(key string, setting *time.Duration) {
+	if env := os.Getenv(key); env != "" {
+		parsedDuration, err := strconv.ParseInt(env, 10, 64)
+		if err != nil {
+			panic(err)
+		}
+		*setting = time.Duration(parsedDuration) * time.Millisecond
 	}
 }
 
@@ -175,6 +195,10 @@ func EnrichOptionsWithOptionsForTesting(t *testing.T, _options ...options.WithOp
 	_options = append(_options,
 		options.WithCustomLogger(ProduceTestingLogger(t)),
 		options.WithPassLoggerToModel(passLoggerToModel),
+		options.WithReceiveTimeout(receiveTimeout),
+		options.WithTraceTransactionManagerWorkers(traceTransactionManagerWorkers),
+		options.WithTraceTransactionManagerTransactions(traceTransactionManagerTransactions),
+		options.WithTraceDefaultMessageCodecWorker(traceDefaultMessageCodecWorker),
 		options.WithExecutorOptionTracerWorkers(traceExecutorWorkers),
 	)
 	// We always create a custom executor to ensure shared executor for transaction manager is not used for tests