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 77453bf1c465ae4c069e3152b9f605af5be07a0f Author: Sebastian Rühl <sru...@apache.org> AuthorDate: Tue Jun 20 17:16:36 2023 +0200 fix(plc4go/spi): increase sleep times of DriverTestRunner --- plc4go/spi/testutils/DriverTestRunner.go | 50 +++++++++++++++----------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/plc4go/spi/testutils/DriverTestRunner.go b/plc4go/spi/testutils/DriverTestRunner.go index 15a11e3a68..b5a639ca2b 100644 --- a/plc4go/spi/testutils/DriverTestRunner.go +++ b/plc4go/spi/testutils/DriverTestRunner.go @@ -92,13 +92,13 @@ type TestTransportInstance interface { } func (m DriverTestsuite) Run(t *testing.T, driverManager plc4go.PlcDriverManager, testcase DriverTestcase) error { - var options []string + var driverParameters []string for key, value := range m.driverParameters { - options = append(options, fmt.Sprintf("%s=%s", key, value)) + driverParameters = append(driverParameters, fmt.Sprintf("%s=%s", key, value)) } optionsString := "" - if len(options) > 0 { - optionsString = "?" + strings.Join(options, "&") + if len(driverParameters) > 0 { + optionsString = "?" + strings.Join(driverParameters, "&") } // Get a connection connectionChan := driverManager.GetConnection(m.driverName + ":test://hurz" + optionsString) @@ -119,8 +119,9 @@ func (m DriverTestsuite) Run(t *testing.T, driverManager plc4go.PlcDriverManager return errors.Wrap(err, "error in setup step "+testStep.name) } // We sleep a bit to not run too fast into the post setup steps and give connections a bit time to settle built up - time.Sleep(10 * time.Millisecond) + time.Sleep(100 * time.Millisecond) // TODO: this is really bad as on CI sometimes those sleeps are not enough... } + t.Log("setup done") // Run the actual scenario steps t.Logf("\n-------------------------------------------------------\nRunning testcases for: %s \n-------------------------------------------------------\n", testcase.name) @@ -129,8 +130,9 @@ func (m DriverTestsuite) Run(t *testing.T, driverManager plc4go.PlcDriverManager if err != nil { return errors.Wrap(err, "error in step "+testStep.name) } - time.Sleep(10 * time.Millisecond) + time.Sleep(100 * time.Millisecond) // TODO: this is really bad as on CI sometimes those sleeps are not enough... } + t.Log("test steps done") // Run the teardown steps t.Logf("\n-------------------------------------------------------\nPerforming teardown for: %s \n-------------------------------------------------------\n", testcase.name) @@ -139,8 +141,9 @@ func (m DriverTestsuite) Run(t *testing.T, driverManager plc4go.PlcDriverManager if err != nil { return errors.Wrap(err, "error in teardown step "+testStep.name) } - time.Sleep(10 * time.Millisecond) + time.Sleep(100 * time.Millisecond) // TODO: this is really bad as on CI sometimes those sleeps are not enough... } + t.Log("tear down done") t.Logf("\n-------------------------------------------------------\nDone\n-------------------------------------------------------\n") return nil @@ -176,8 +179,7 @@ func (m DriverTestsuite) ExecuteStep(t *testing.T, connection plc4go.PlcConnecti } // Execute the read-request and store the response-channel in the testcase. - t.Logf("Execute read request (%T)", readRequest) - t.Logf("\n%s", readRequest) + t.Logf("Execute read request (%T)\n%[1]s", readRequest) if testcase.readRequestResultChannel != nil { return errors.New("testcase read-request result channel already occupied") } @@ -213,8 +215,7 @@ func (m DriverTestsuite) ExecuteStep(t *testing.T, connection plc4go.PlcConnecti if err != nil { return errors.Wrap(err, "Error creating write-request") } - t.Logf("Execute write request (%T)", writeRequest) - t.Logf("\n%s", writeRequest) + t.Logf("Execute write request (%T)\n%[1]s", writeRequest) if testcase.writeRequestResultChannel != nil { return errors.New("testcase write-request result channel already occupied") } @@ -235,8 +236,7 @@ func (m DriverTestsuite) ExecuteStep(t *testing.T, connection plc4go.PlcConnecti // Serialize the response to XML xmlWriteBuffer := utils.NewXmlWriteBuffer() response := readRequestResult.GetResponse() - t.Logf("Got response (%T)", response) - t.Logf("\n%s", response) + t.Logf("Got response (%T)\n%[1]s", response) err := response.(utils.Serializable).SerializeWithWriteBuffer(context.Background(), xmlWriteBuffer) if err != nil { return errors.Wrap(err, "error serializing response") @@ -263,8 +263,7 @@ func (m DriverTestsuite) ExecuteStep(t *testing.T, connection plc4go.PlcConnecti // Serialize the response to XML xmlWriteBuffer := utils.NewXmlWriteBuffer() response := writeResponseResult.GetResponse() - t.Logf("Got response (%T)", response) - t.Logf("\n%s", response) + t.Logf("Got response (%T)\n%[1]s", response) err := response.(utils.Serializable).SerializeWithWriteBuffer(context.Background(), xmlWriteBuffer) if err != nil { return errors.Wrap(err, "error serializing response") @@ -290,8 +289,7 @@ func (m DriverTestsuite) ExecuteStep(t *testing.T, connection plc4go.PlcConnecti if err != nil { return errors.Wrap(err, "Error parsing message") } - t.Logf("Parsed message (%T)", expectedMessage) - t.Logf("\n%s", expectedMessage) + t.Logf("Parsed message (%T)\n%[1]s", expectedMessage) // Serialize the model into bytes t.Log("Write to bytes") @@ -312,11 +310,11 @@ func (m DriverTestsuite) ExecuteStep(t *testing.T, connection plc4go.PlcConnecti expectedRawOutput := expectedWriteBuffer.GetBytes() expectedRawOutputLength := uint32(len(expectedRawOutput)) - now := time.Now() + startTransportPolling := time.Now() // Read exactly this amount of bytes from the transport - t.Logf("Reading bytes (expectedRawOutputLength %d)", expectedRawOutputLength) + t.Logf("Reading bytes from transport instance (expectedRawOutputLength %d)", expectedRawOutputLength) for testTransportInstance.GetNumDrainableBytes() < expectedRawOutputLength { - if time.Now().Sub(now) > 2*time.Second { + if time.Since(startTransportPolling) > 2*time.Second { drainableBytes := testTransportInstance.GetNumDrainableBytes() actualRawOutput := testTransportInstance.DrainWriteBuffer(drainableBytes) return errors.Errorf("error getting bytes from transport. Not enough data available: actual(%d)<expected(%d), \nactual: %#X\nexpected: %#X\nHexdumps:\n%s", @@ -349,6 +347,7 @@ func (m DriverTestsuite) ExecuteStep(t *testing.T, connection plc4go.PlcConnecti return errors.Errorf("actual output doesn't match expected output:\nactual: %#X\nexpected: %#X\nHexdumps:\n%s", actualRawOutput, expectedRawOutput, utils.DiffHex(expectedRawOutput, actualRawOutput)) } } + t.Log("outputs are matching") // If there's a difference, parse the input and display it to simplify debugging case StepTypeOutgoingPlcBytes: // Read exactly this amount of bytes from the transport @@ -378,8 +377,7 @@ func (m DriverTestsuite) ExecuteStep(t *testing.T, connection plc4go.PlcConnecti if err != nil { return errors.Wrap(err, "error parsing message") } - t.Logf("Parsed message (%T)", expectedMessage) - t.Logf("\n%s", expectedMessage) + t.Logf("Parsed message (%T)\n%[1]s", expectedMessage) // Serialize the model into bytes t.Log("Serializing bytes") @@ -399,9 +397,8 @@ func (m DriverTestsuite) ExecuteStep(t *testing.T, connection plc4go.PlcConnecti } // Send these bytes to the transport - t.Log("Writing to transport") _bytes := wb.GetBytes() - t.Logf("\n%s", hex.Dump(_bytes)) + t.Logf("Writing to transport\n%s", hex.Dump(_bytes)) testTransportInstance.FillReadBuffer(_bytes) case StepTypeIncomingPlcBytes: // Get the raw hex-data. @@ -412,8 +409,7 @@ func (m DriverTestsuite) ExecuteStep(t *testing.T, connection plc4go.PlcConnecti } // Send these bytes to the transport - t.Log("Writing bytes to transport") - t.Logf("\n%s", hex.Dump(rawInput)) + t.Logf("Writing bytes to transport\n%[1]s", hex.Dump(rawInput)) testTransportInstance.FillReadBuffer(rawInput) case StepTypeDelay: // Get the number of milliseconds @@ -433,7 +429,7 @@ func (m DriverTestsuite) ExecuteStep(t *testing.T, connection plc4go.PlcConnecti return errors.Wrap(err, "error closing transport") } } - t.Logf("\n-------------------------------------------------------\n - Finished step: %s after %vms \n-------------------------------------------------------", step.name, time.Now().Sub(start).Milliseconds()) + t.Logf("\n-------------------------------------------------------\n - Finished step: %s after %sms \n-------------------------------------------------------", step.name, time.Since(start)) return nil }