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 0b1a56dc03 fix(plc4go): remove clean timer (go fixed 1.23)
0b1a56dc03 is described below
commit 0b1a56dc031df3d404d0603f3e0bccba52b67538
Author: Sebastian Rühl <[email protected]>
AuthorDate: Thu Mar 6 12:32:04 2025 +0100
fix(plc4go): remove clean timer (go fixed 1.23)
---
plc4go/internal/bacnetip/Connection.go | 2 --
.../bacnetip/bacgopes/iocb/iocb_IOQueue.go | 2 --
plc4go/internal/cbus/Browser_test.go | 10 ------
plc4go/internal/cbus/Connection.go | 3 --
plc4go/internal/cbus/Connection_test.go | 10 ------
plc4go/internal/cbus/Discoverer.go | 3 --
plc4go/internal/cbus/Discoverer_test.go | 2 --
plc4go/internal/cbus/Driver_test.go | 6 ----
plc4go/internal/cbus/Reader_test.go | 8 -----
plc4go/internal/cbus/Writer_test.go | 4 ---
plc4go/internal/eip/Connection.go | 3 --
plc4go/internal/simulated/Connection_test.go | 5 ---
plc4go/internal/simulated/Driver_test.go | 2 --
plc4go/internal/simulated/Reader_test.go | 2 --
plc4go/internal/simulated/Writer_test.go | 2 --
plc4go/pkg/api/PlcDriverManger_test.go | 10 ------
plc4go/pkg/api/cache/PlcConnectionCache.go | 11 +++----
plc4go/spi/default/DefaultBrowser_test.go | 4 ---
plc4go/spi/default/DefaultCodec.go | 3 +-
plc4go/spi/default/DefaultConnection_test.go | 5 ---
plc4go/spi/model/DefaultPlcReadRequest_test.go | 13 --------
plc4go/spi/model/DefaultPlcWriteRequest_test.go | 13 --------
plc4go/spi/pool/dynamicExecutor.go | 4 ---
plc4go/spi/testutils/DriverTestRunner.go | 4 ---
.../spi/transactions/RequestTransactionManager.go | 2 --
plc4go/spi/utils/Net.go | 2 --
plc4go/spi/utils/common.go | 16 ----------
plc4go/spi/utils/common_test.go | 36 ----------------------
.../tests/drivers/tests/manual_cbus_driver_test.go | 2 --
29 files changed, 5 insertions(+), 184 deletions(-)
diff --git a/plc4go/internal/bacnetip/Connection.go
b/plc4go/internal/bacnetip/Connection.go
index 2fd9fd7e17..b6ea919934 100644
--- a/plc4go/internal/bacnetip/Connection.go
+++ b/plc4go/internal/bacnetip/Connection.go
@@ -37,7 +37,6 @@ import (
"github.com/apache/plc4x/plc4go/spi/options"
"github.com/apache/plc4x/plc4go/spi/tracer"
"github.com/apache/plc4x/plc4go/spi/transactions"
- "github.com/apache/plc4x/plc4go/spi/utils"
)
type Connection struct {
@@ -117,7 +116,6 @@ func (c *Connection) ConnectWithContext(ctx
context.Context) <-chan plc4go.PlcCo
func (c *Connection) passToDefaultIncomingMessageChannel() {
incomingMessageChannel :=
c.messageCodec.GetDefaultIncomingMessageChannel()
timeout := time.NewTimer(20 * time.Millisecond)
- defer utils.CleanupTimer(timeout)
select {
case message := <-incomingMessageChannel:
// TODO: implement mapping to subscribers
diff --git a/plc4go/internal/bacnetip/bacgopes/iocb/iocb_IOQueue.go
b/plc4go/internal/bacnetip/bacgopes/iocb/iocb_IOQueue.go
index 38d0ea9692..6ac9a31c10 100644
--- a/plc4go/internal/bacnetip/bacgopes/iocb/iocb_IOQueue.go
+++ b/plc4go/internal/bacnetip/bacgopes/iocb/iocb_IOQueue.go
@@ -28,7 +28,6 @@ import (
"github.com/rs/zerolog"
. "github.com/apache/plc4x/plc4go/internal/bacnetip/bacgopes/comp"
- "github.com/apache/plc4x/plc4go/spi/utils"
)
//go:generate go tool plc4xGenerator -type=IOQueue -prefix=iocb_
@@ -94,7 +93,6 @@ func (i *IOQueue) Get(block bool, delay *time.Duration)
(IOCBContract, error) {
close(gotSomething)
}()
timeout := time.NewTimer(*delay)
- defer utils.CleanupTimer(timeout)
select {
case <-gotSomething:
case <-timeout.C:
diff --git a/plc4go/internal/cbus/Browser_test.go
b/plc4go/internal/cbus/Browser_test.go
index 6707861cdc..6fc3e7376a 100644
--- a/plc4go/internal/cbus/Browser_test.go
+++ b/plc4go/internal/cbus/Browser_test.go
@@ -43,7 +43,6 @@ import (
"github.com/apache/plc4x/plc4go/spi/testutils"
"github.com/apache/plc4x/plc4go/spi/transports"
"github.com/apache/plc4x/plc4go/spi/transports/test"
- "github.com/apache/plc4x/plc4go/spi/utils"
spiValues "github.com/apache/plc4x/plc4go/spi/values"
)
@@ -168,9 +167,6 @@ func TestBrowser_BrowseQuery(t *testing.T) {
fields.connection =
connectionConnectResult.GetConnection()
t.Cleanup(func() {
timer := time.NewTimer(10 * time.Second)
- t.Cleanup(func() {
- utils.CleanupTimer(timer)
- })
select {
case <-fields.connection.Close():
case <-timer.C:
@@ -327,9 +323,6 @@ func TestBrowser_browseUnitInfo(t *testing.T) {
fields.connection =
connectionConnectResult.GetConnection()
t.Cleanup(func() {
timer := time.NewTimer(10 * time.Second)
- t.Cleanup(func() {
- utils.CleanupTimer(timer)
- })
select {
case <-fields.connection.Close():
case <-timer.C:
@@ -601,9 +594,6 @@ func TestBrowser_getInstalledUnitAddressBytes(t *testing.T)
{
fields.connection =
connectionConnectResult.GetConnection()
t.Cleanup(func() {
timer := time.NewTimer(6 * time.Second)
- t.Cleanup(func() {
- utils.CleanupTimer(timer)
- })
select {
case <-fields.connection.Close():
case <-timer.C:
diff --git a/plc4go/internal/cbus/Connection.go
b/plc4go/internal/cbus/Connection.go
index ef5b6cfc2d..6ec4bd9c0e 100644
--- a/plc4go/internal/cbus/Connection.go
+++ b/plc4go/internal/cbus/Connection.go
@@ -37,7 +37,6 @@ import (
"github.com/apache/plc4x/plc4go/spi/options"
"github.com/apache/plc4x/plc4go/spi/tracer"
"github.com/apache/plc4x/plc4go/spi/transactions"
- "github.com/apache/plc4x/plc4go/spi/utils"
)
//go:generate go tool plc4xGenerator -type=AlphaGenerator
@@ -432,7 +431,6 @@ func (c *Connection) sendReset(ctx context.Context, ch chan
plc4go.PlcConnection
startTime := time.Now()
timeout := time.NewTimer(time.Millisecond * 500)
- defer utils.CleanupTimer(timeout)
select {
case <-receivedResetEchoChan:
c.log.Debug().Msg("We received the echo")
@@ -586,7 +584,6 @@ func (c *Connection) sendCalDataWrite(ctx context.Context,
ch chan plc4go.PlcCon
startTime := time.Now()
timeout := time.NewTimer(2 * time.Second)
- defer utils.CleanupTimer(timeout)
select {
case <-directCommandAckChan:
c.log.Debug().Msg("We received the ack")
diff --git a/plc4go/internal/cbus/Connection_test.go
b/plc4go/internal/cbus/Connection_test.go
index 8696ba22f2..b59f3d465d 100644
--- a/plc4go/internal/cbus/Connection_test.go
+++ b/plc4go/internal/cbus/Connection_test.go
@@ -42,7 +42,6 @@ import (
"github.com/apache/plc4x/plc4go/spi/tracer"
"github.com/apache/plc4x/plc4go/spi/transactions"
"github.com/apache/plc4x/plc4go/spi/transports/test"
- "github.com/apache/plc4x/plc4go/spi/utils"
)
func TestAlphaGenerator_getAndIncrement(t *testing.T) {
@@ -1635,9 +1634,6 @@ func TestConnection_setupConnection(t *testing.T) {
c.setupConnection(tt.args.ctx, tt.args.ch)
assert.NotNil(t, tt.args.ch, "We always need a result
channel")
chanTimeout := time.NewTimer(10 * time.Second)
- t.Cleanup(func() {
- utils.CleanupTimer(chanTimeout)
- })
select {
case <-chanTimeout.C:
t.Fatal("setup connection doesn't fill chan in
time")
@@ -1648,9 +1644,6 @@ func TestConnection_setupConnection(t *testing.T) {
}
// To shut down properly we always do that
closeTimeout := time.NewTimer(10 * time.Second)
- t.Cleanup(func() {
- utils.CleanupTimer(closeTimeout)
- })
select {
case <-closeTimeout.C:
t.Fatal("close didn't react in time")
@@ -1820,9 +1813,6 @@ func TestNewConnection(t *testing.T) {
connection := NewConnection(tt.args.messageCodec,
tt.args.configuration, tt.args.driverContext, tt.args.tagHandler, tt.args.tm,
tt.args.options, tt.args._options...)
t.Cleanup(func() {
timer := time.NewTimer(1 * time.Second)
- t.Cleanup(func() {
- utils.CleanupTimer(timer)
- })
select {
case <-connection.Close():
case <-timer.C:
diff --git a/plc4go/internal/cbus/Discoverer.go
b/plc4go/internal/cbus/Discoverer.go
index 18f17e9b12..1acb4e54aa 100644
--- a/plc4go/internal/cbus/Discoverer.go
+++ b/plc4go/internal/cbus/Discoverer.go
@@ -298,13 +298,10 @@ func (d *Discoverer)
createDeviceScanDispatcher(tcpTransportInstance *tcp.Transp
// Keep on reading responses till the timeout is done.
// TODO: Make this configurable
timeout := time.NewTimer(1 * time.Second)
- defer utils.CleanupTimer(timeout)
for start := time.Now(); time.Since(start) < 5*time.Second; {
timeout.Reset(1 * time.Second)
select {
case receivedMessage :=
<-codec.GetDefaultIncomingMessageChannel():
- // Cleanup, going to be resetted again
- utils.CleanupTimer(timeout)
cbusMessage, ok :=
receivedMessage.(readWriteModel.CBusMessage)
if !ok {
continue
diff --git a/plc4go/internal/cbus/Discoverer_test.go
b/plc4go/internal/cbus/Discoverer_test.go
index ecae17c5b7..50fe308ff7 100644
--- a/plc4go/internal/cbus/Discoverer_test.go
+++ b/plc4go/internal/cbus/Discoverer_test.go
@@ -40,7 +40,6 @@ import (
"github.com/apache/plc4x/plc4go/spi/testutils"
"github.com/apache/plc4x/plc4go/spi/transports"
"github.com/apache/plc4x/plc4go/spi/transports/tcp"
- "github.com/apache/plc4x/plc4go/spi/utils"
)
func TestNewDiscoverer(t *testing.T) {
@@ -332,7 +331,6 @@ func TestDiscoverer_createTransportInstanceDispatcher(t
*testing.T) {
assert.NotNilf(t, dispatcher,
"createTransportInstanceDispatcher(%v, %v, %v, %v, %v)", tt.args.ctx,
tt.args.wg, tt.args.ip, tt.args.tcpTransport, tt.args.transportInstances)
dispatcher()
timeout := time.NewTimer(2 * time.Second)
- defer utils.CleanupTimer(timeout)
select {
case <-timeout.C:
t.Error("timeout")
diff --git a/plc4go/internal/cbus/Driver_test.go
b/plc4go/internal/cbus/Driver_test.go
index bb340c6bb9..3ad4eff462 100644
--- a/plc4go/internal/cbus/Driver_test.go
+++ b/plc4go/internal/cbus/Driver_test.go
@@ -37,7 +37,6 @@ import (
"github.com/apache/plc4x/plc4go/spi/transactions"
"github.com/apache/plc4x/plc4go/spi/transports"
"github.com/apache/plc4x/plc4go/spi/transports/test"
- "github.com/apache/plc4x/plc4go/spi/utils"
)
func TestDriver_DiscoverWithContext(t *testing.T) {
@@ -135,7 +134,6 @@ func TestDriver_GetConnectionWithContext(t *testing.T) {
},
wantVerifier: func(t *testing.T, results <-chan
plc4go.PlcConnectionConnectResult) bool {
timeout := time.NewTimer(20 * time.Millisecond)
- defer utils.CleanupTimer(timeout)
select {
case <-timeout.C:
t.Error("timeout")
@@ -168,7 +166,6 @@ func TestDriver_GetConnectionWithContext(t *testing.T) {
},
wantVerifier: func(t *testing.T, results <-chan
plc4go.PlcConnectionConnectResult) bool {
timeout := time.NewTimer(20 * time.Millisecond)
- defer utils.CleanupTimer(timeout)
select {
case <-timeout.C:
t.Error("timeout")
@@ -202,7 +199,6 @@ func TestDriver_GetConnectionWithContext(t *testing.T) {
},
wantVerifier: func(t *testing.T, results <-chan
plc4go.PlcConnectionConnectResult) bool {
timeout := time.NewTimer(20 * time.Millisecond)
- defer utils.CleanupTimer(timeout)
select {
case <-timeout.C:
t.Error("timeout")
@@ -233,7 +229,6 @@ func TestDriver_GetConnectionWithContext(t *testing.T) {
},
wantVerifier: func(t *testing.T, results <-chan
plc4go.PlcConnectionConnectResult) bool {
timeout := time.NewTimer(20 * time.Millisecond)
- defer utils.CleanupTimer(timeout)
select {
case <-timeout.C:
t.Error("timeout")
@@ -325,7 +320,6 @@ func TestDriver_reportError(t *testing.T) {
},
wantAsserter: func(t *testing.T, results <-chan
plc4go.PlcConnectionConnectResult) bool {
timeout := time.NewTimer(20 * time.Millisecond)
- defer utils.CleanupTimer(timeout)
select {
case <-timeout.C:
t.Error("timeout")
diff --git a/plc4go/internal/cbus/Reader_test.go
b/plc4go/internal/cbus/Reader_test.go
index edd4591584..b85e7ce80a 100644
--- a/plc4go/internal/cbus/Reader_test.go
+++ b/plc4go/internal/cbus/Reader_test.go
@@ -42,7 +42,6 @@ import (
"github.com/apache/plc4x/plc4go/spi/testutils"
"github.com/apache/plc4x/plc4go/spi/transactions"
"github.com/apache/plc4x/plc4go/spi/transports/test"
- "github.com/apache/plc4x/plc4go/spi/utils"
)
func TestNewReader(t *testing.T) {
@@ -105,7 +104,6 @@ func TestReader_Read(t *testing.T) {
},
wantAsserter: func(t *testing.T, results <-chan
apiModel.PlcReadRequestResult) bool {
timer := time.NewTimer(2 * time.Second)
- defer utils.CleanupTimer(timer)
select {
case <-timer.C:
t.Fail()
@@ -163,7 +161,6 @@ func TestReader_readSync(t *testing.T) {
},
resultEvaluator: func(t *testing.T, results chan
apiModel.PlcReadRequestResult) bool {
timer := time.NewTimer(2 * time.Second)
- defer utils.CleanupTimer(timer)
select {
case <-timer.C:
t.Fail()
@@ -213,7 +210,6 @@ func TestReader_readSync(t *testing.T) {
},
resultEvaluator: func(t *testing.T, results chan
apiModel.PlcReadRequestResult) bool {
timer := time.NewTimer(2 * time.Second)
- defer utils.CleanupTimer(timer)
select {
case <-timer.C:
t.Fail()
@@ -239,7 +235,6 @@ func TestReader_readSync(t *testing.T) {
},
resultEvaluator: func(t *testing.T, results chan
apiModel.PlcReadRequestResult) bool {
timer := time.NewTimer(2 * time.Second)
- defer utils.CleanupTimer(timer)
select {
case <-timer.C:
t.Fail()
@@ -316,7 +311,6 @@ func TestReader_readSync(t *testing.T) {
},
resultEvaluator: func(t *testing.T, results chan
apiModel.PlcReadRequestResult) bool {
timer := time.NewTimer(2 * time.Second)
- defer utils.CleanupTimer(timer)
select {
case <-timer.C:
t.Fail()
@@ -379,7 +373,6 @@ func TestReader_readSync(t *testing.T) {
},
resultEvaluator: func(t *testing.T, results chan
apiModel.PlcReadRequestResult) bool {
timer := time.NewTimer(2 * time.Second)
- defer utils.CleanupTimer(timer)
select {
case <-timer.C:
t.Fail()
@@ -1148,7 +1141,6 @@ func TestReader_sendMessageOverTheWire(t *testing.T) {
m.sendMessageOverTheWire(tt.args.ctx,
tt.args.transaction, tt.args.messageToSend, tt.args.addResponseCode(t),
tt.args.tagName, tt.args.addPlcValue(t))
t.Log("Waiting now")
timer := time.NewTimer(10 * time.Second)
- defer utils.CleanupTimer(timer)
select {
case <-ch:
t.Log("Done waiting")
diff --git a/plc4go/internal/cbus/Writer_test.go
b/plc4go/internal/cbus/Writer_test.go
index 89a983c8ab..1d5ce033d9 100644
--- a/plc4go/internal/cbus/Writer_test.go
+++ b/plc4go/internal/cbus/Writer_test.go
@@ -32,7 +32,6 @@ import (
spiModel "github.com/apache/plc4x/plc4go/spi/model"
"github.com/apache/plc4x/plc4go/spi/testutils"
"github.com/apache/plc4x/plc4go/spi/transactions"
- "github.com/apache/plc4x/plc4go/spi/utils"
)
func TestNewWriter(t *testing.T) {
@@ -89,7 +88,6 @@ func TestWriter_Write(t *testing.T) {
},
wantAsserter: func(t *testing.T, results <-chan
apiModel.PlcWriteRequestResult) bool {
timeout := time.NewTimer(2 * time.Second)
- defer utils.CleanupTimer(timeout)
select {
case <-timeout.C:
t.Error("timeout")
@@ -113,7 +111,6 @@ func TestWriter_Write(t *testing.T) {
},
wantAsserter: func(t *testing.T, results <-chan
apiModel.PlcWriteRequestResult) bool {
timeout := time.NewTimer(2 * time.Second)
- defer utils.CleanupTimer(timeout)
select {
case <-timeout.C:
t.Fatal("timeout")
@@ -161,7 +158,6 @@ func TestWriter_Write(t *testing.T) {
},
wantAsserter: func(t *testing.T, results <-chan
apiModel.PlcWriteRequestResult) bool {
timeout := time.NewTimer(2 *
time.Second)
- utils.CleanupTimer(timeout)
select {
case <-timeout.C:
t.Error("timeout")
diff --git a/plc4go/internal/eip/Connection.go
b/plc4go/internal/eip/Connection.go
index a291319fa7..a488f466be 100644
--- a/plc4go/internal/eip/Connection.go
+++ b/plc4go/internal/eip/Connection.go
@@ -258,7 +258,6 @@ func (c *Connection) listServiceRequest(ctx
context.Context, ch chan plc4go.PlcC
}
timeout := time.NewTimer(1 * time.Second)
- defer utils.CleanupTimer(timeout)
select {
case <-timeout.C:
return errors.New("timeout")
@@ -381,7 +380,6 @@ func (c *Connection) connectRegisterSession(ctx
context.Context, ch chan plc4go.
c.fireConnectionError(errors.Wrap(err, "Error during sending of
EIP ListServices Request"), ch)
}
timeout := time.NewTimer(1 * time.Second)
- defer utils.CleanupTimer(timeout)
select {
case <-timeout.C:
return errors.New("timeout")
@@ -460,7 +458,6 @@ func (c *Connection) listAllAttributes(ctx context.Context,
ch chan plc4go.PlcCo
}
timeout := time.NewTimer(1 * time.Second)
- defer utils.CleanupTimer(timeout)
select {
case <-timeout.C:
return errors.New("timeout")
diff --git a/plc4go/internal/simulated/Connection_test.go
b/plc4go/internal/simulated/Connection_test.go
index ee7b34c69b..9b26161ef1 100644
--- a/plc4go/internal/simulated/Connection_test.go
+++ b/plc4go/internal/simulated/Connection_test.go
@@ -30,7 +30,6 @@ import (
"github.com/apache/plc4x/plc4go/spi"
_default "github.com/apache/plc4x/plc4go/spi/default"
spiModel "github.com/apache/plc4x/plc4go/spi/model"
- "github.com/apache/plc4x/plc4go/spi/utils"
)
func TestConnection_Connect(t *testing.T) {
@@ -126,7 +125,6 @@ func TestConnection_Connect(t *testing.T) {
timeBeforeConnect := time.Now()
connectionChan := c.Connect()
timeout := time.NewTimer(3 * time.Second)
- defer utils.CleanupTimer(timeout)
select {
case connectResult := <-connectionChan:
timeAfterConnect := time.Now()
@@ -243,7 +241,6 @@ func TestConnection_Close(t *testing.T) {
timeBeforeClose := time.Now()
closeChan := c.Close()
timeout := time.NewTimer(3 * time.Second)
- defer utils.CleanupTimer(timeout)
select {
case closeResult := <-closeChan:
timeAfterClose := time.Now()
@@ -338,7 +335,6 @@ func TestConnection_BlockingClose(t *testing.T) {
return ch
}
timeout := time.NewTimer(3 * time.Second)
- defer utils.CleanupTimer(timeout)
select {
case <-executor():
timeAfterClose := time.Now()
@@ -509,7 +505,6 @@ func TestConnection_Ping(t *testing.T) {
timeBeforePing := time.Now()
pingChan := c.Ping()
timeout := time.NewTimer(3 * time.Second)
- defer utils.CleanupTimer(timeout)
select {
case pingResult := <-pingChan:
timeAfterPing := time.Now()
diff --git a/plc4go/internal/simulated/Driver_test.go
b/plc4go/internal/simulated/Driver_test.go
index 2a09e3f88d..3c8de0d7db 100644
--- a/plc4go/internal/simulated/Driver_test.go
+++ b/plc4go/internal/simulated/Driver_test.go
@@ -28,7 +28,6 @@ import (
"github.com/apache/plc4x/plc4go/spi/options"
"github.com/apache/plc4x/plc4go/spi/testutils"
"github.com/apache/plc4x/plc4go/spi/transports"
- "github.com/apache/plc4x/plc4go/spi/utils"
)
func TestDriver_CheckQuery(t *testing.T) {
@@ -134,7 +133,6 @@ func TestDriver_GetConnection(t *testing.T) {
d :=
NewDriver(options.WithCustomLogger(testutils.ProduceTestingLogger(t)))
connectionChan := d.GetConnection(tt.args.in0,
tt.args.in1, tt.args.options)
timeout := time.NewTimer(3 * time.Second)
- defer utils.CleanupTimer(timeout)
select {
case connectResult := <-connectionChan:
if tt.wantErr && (connectResult.GetErr() ==
nil) {
diff --git a/plc4go/internal/simulated/Reader_test.go
b/plc4go/internal/simulated/Reader_test.go
index 1538262c57..1f84b7fb5b 100644
--- a/plc4go/internal/simulated/Reader_test.go
+++ b/plc4go/internal/simulated/Reader_test.go
@@ -33,7 +33,6 @@ import (
spiModel "github.com/apache/plc4x/plc4go/spi/model"
"github.com/apache/plc4x/plc4go/spi/options"
"github.com/apache/plc4x/plc4go/spi/testutils"
- "github.com/apache/plc4x/plc4go/spi/utils"
spiValues "github.com/apache/plc4x/plc4go/spi/values"
)
@@ -168,7 +167,6 @@ func TestReader_Read(t *testing.T) {
timeBeforeReadRequest := time.Now()
readResponseChannel := r.Read(testutils.TestContext(t),
readRequest)
timeout := time.NewTimer(3 * time.Second)
- defer utils.CleanupTimer(timeout)
select {
case readResponse := <-readResponseChannel:
timeAfterReadRequest := time.Now()
diff --git a/plc4go/internal/simulated/Writer_test.go
b/plc4go/internal/simulated/Writer_test.go
index 5cf1395d55..b80241dae5 100644
--- a/plc4go/internal/simulated/Writer_test.go
+++ b/plc4go/internal/simulated/Writer_test.go
@@ -33,7 +33,6 @@ import (
spiModel "github.com/apache/plc4x/plc4go/spi/model"
"github.com/apache/plc4x/plc4go/spi/options"
"github.com/apache/plc4x/plc4go/spi/testutils"
- "github.com/apache/plc4x/plc4go/spi/utils"
spiValues "github.com/apache/plc4x/plc4go/spi/values"
)
@@ -180,7 +179,6 @@ func TestWriter_Write(t *testing.T) {
timeBeforeWriteRequest := time.Now()
writeResponseChannel :=
w.Write(testutils.TestContext(t), writeRequest)
timeout := time.NewTimer(3 * time.Second)
- defer utils.CleanupTimer(timeout)
select {
case writeResponse := <-writeResponseChannel:
timeAfterWriteRequest := time.Now()
diff --git a/plc4go/pkg/api/PlcDriverManger_test.go
b/plc4go/pkg/api/PlcDriverManger_test.go
index 7fbc37a0a2..d2033ac7f8 100644
--- a/plc4go/pkg/api/PlcDriverManger_test.go
+++ b/plc4go/pkg/api/PlcDriverManger_test.go
@@ -34,7 +34,6 @@ import (
"github.com/apache/plc4x/plc4go/pkg/api/model"
"github.com/apache/plc4x/plc4go/spi/options"
"github.com/apache/plc4x/plc4go/spi/transports"
- "github.com/apache/plc4x/plc4go/spi/utils"
)
func TestNewPlcDriverManager(t *testing.T) {
@@ -449,9 +448,6 @@ func Test_plcDriverManger_GetConnection(t *testing.T) {
},
wantVerifier: func(t *testing.T, results <-chan
PlcConnectionConnectResult) bool {
timeout := time.NewTimer(3 * time.Second)
- t.Cleanup(func() {
- utils.CleanupTimer(timeout)
- })
select {
case <-timeout.C:
t.Error("timeout")
@@ -467,9 +463,6 @@ func Test_plcDriverManger_GetConnection(t *testing.T) {
name: "get one without a driver",
wantVerifier: func(t *testing.T, results <-chan
PlcConnectionConnectResult) bool {
timeout := time.NewTimer(3 * time.Second)
- t.Cleanup(func() {
- utils.CleanupTimer(timeout)
- })
select {
case <-timeout.C:
t.Error("timeout")
@@ -504,9 +497,6 @@ func Test_plcDriverManger_GetConnection(t *testing.T) {
},
wantVerifier: func(t *testing.T, results <-chan
PlcConnectionConnectResult) bool {
timeout := time.NewTimer(3 * time.Second)
- t.Cleanup(func() {
- utils.CleanupTimer(timeout)
- })
select {
case <-timeout.C:
t.Error("timeout")
diff --git a/plc4go/pkg/api/cache/PlcConnectionCache.go
b/plc4go/pkg/api/cache/PlcConnectionCache.go
index 7d580742bc..93c34ee8d0 100644
--- a/plc4go/pkg/api/cache/PlcConnectionCache.go
+++ b/plc4go/pkg/api/cache/PlcConnectionCache.go
@@ -33,7 +33,6 @@ import (
_default "github.com/apache/plc4x/plc4go/spi/default"
"github.com/apache/plc4x/plc4go/spi/options"
"github.com/apache/plc4x/plc4go/spi/tracer"
- "github.com/apache/plc4x/plc4go/spi/utils"
)
type PlcConnectionCache interface {
@@ -186,15 +185,16 @@ func (c *plcConnectionCache) GetConnectionWithContext(ctx
context.Context, conne
}
leaseChan := connection.lease()
maximumWaitTimeout := time.NewTimer(c.maxWaitTime)
- defer utils.CleanupTimer(maximumWaitTimeout)
select {
case <-ctx.Done(): // abort on context cancel
ch <- _default.NewDefaultPlcConnectionCloseResult(nil,
ctx.Err())
case connectionResponse := <-leaseChan: // Wait till we get a
lease.
- c.log.Debug().Str("connectionString",
connectionString).Msg("Successfully got lease to connection")
+ c.log.Debug().
+ Str("connectionString", connectionString).
+ Stringer("connectionResponse",
connectionResponse).
+ Msg("Successfully got lease to connection")
responseTimeout := time.NewTimer(10 * time.Millisecond)
- defer utils.CleanupTimer(responseTimeout)
select {
case ch <- connectionResponse:
if c.tracer != nil {
@@ -240,7 +240,6 @@ func (c *plcConnectionCache) Close() <-chan
PlcConnectionCacheCloseResult {
if len(c.connections) == 0 {
responseDeliveryTimeout := time.NewTimer(10 *
time.Millisecond)
- defer utils.CleanupTimer(responseDeliveryTimeout)
select {
case ch <- newDefaultPlcConnectionCacheCloseResult(c,
nil):
case <-responseDeliveryTimeout.C:
@@ -257,7 +256,6 @@ func (c *plcConnectionCache) Close() <-chan
PlcConnectionCacheCloseResult {
go func(container *connectionContainer) {
leaseResults := container.lease()
closeTimeout := time.NewTimer(c.maxWaitTime)
- defer utils.CleanupTimer(closeTimeout)
select {
// We're just getting the lease as this way we
can be sure nobody else is using it.
// We also really don'c care if it worked, or
not ... it's just an attempt of being
@@ -278,7 +276,6 @@ func (c *plcConnectionCache) Close() <-chan
PlcConnectionCacheCloseResult {
}
responseDeliveryTimeout := time.NewTimer(10 *
time.Millisecond)
- defer
utils.CleanupTimer(responseDeliveryTimeout)
select {
case ch <-
newDefaultPlcConnectionCacheCloseResult(c, nil):
case <-responseDeliveryTimeout.C:
diff --git a/plc4go/spi/default/DefaultBrowser_test.go
b/plc4go/spi/default/DefaultBrowser_test.go
index aa6e8b99b0..331c54bd1d 100644
--- a/plc4go/spi/default/DefaultBrowser_test.go
+++ b/plc4go/spi/default/DefaultBrowser_test.go
@@ -30,7 +30,6 @@ import (
apiModel "github.com/apache/plc4x/plc4go/pkg/api/model"
spiModel "github.com/apache/plc4x/plc4go/spi/model"
- "github.com/apache/plc4x/plc4go/spi/utils"
)
func TestNewDefaultBrowser(t *testing.T) {
@@ -80,7 +79,6 @@ func Test_defaultBrowser_Browse(t *testing.T) {
},
wantAsserter: func(t *testing.T, results <-chan
apiModel.PlcBrowseRequestResult) bool {
timeout := time.NewTimer(2 * time.Second)
- defer utils.CleanupTimer(timeout)
select {
case result := <-results:
assert.NotNil(t, result)
@@ -126,7 +124,6 @@ func Test_defaultBrowser_BrowseWithInterceptor(t
*testing.T) {
},
wantAsserter: func(t *testing.T, results <-chan
apiModel.PlcBrowseRequestResult) bool {
timeout := time.NewTimer(2 * time.Second)
- defer utils.CleanupTimer(timeout)
select {
case result := <-results:
assert.NotNil(t, result)
@@ -161,7 +158,6 @@ func Test_defaultBrowser_BrowseWithInterceptor(t
*testing.T) {
},
wantAsserter: func(t *testing.T, results <-chan
apiModel.PlcBrowseRequestResult) bool {
timeout := time.NewTimer(2 * time.Second)
- defer utils.CleanupTimer(timeout)
select {
case result := <-results:
assert.NotNil(t, result)
diff --git a/plc4go/spi/default/DefaultCodec.go
b/plc4go/spi/default/DefaultCodec.go
index e3c0ff3334..b6875891ef 100644
--- a/plc4go/spi/default/DefaultCodec.go
+++ b/plc4go/spi/default/DefaultCodec.go
@@ -352,9 +352,8 @@ mainLoop:
timeoutTimer := time.NewTimer(m.receiveTimeout)
select {
case <-syncer:
- utils.CleanupTimer(timeoutTimer)
+ // nothing
case <-timeoutTimer.C:
- utils.CleanupTimer(timeoutTimer)
workerLog.Error().Dur("receiveTimeout",
m.receiveTimeout).Msg("receive timeout")
continue mainLoop
}
diff --git a/plc4go/spi/default/DefaultConnection_test.go
b/plc4go/spi/default/DefaultConnection_test.go
index 289043a208..cc023bd9bb 100644
--- a/plc4go/spi/default/DefaultConnection_test.go
+++ b/plc4go/spi/default/DefaultConnection_test.go
@@ -35,7 +35,6 @@ import (
"github.com/apache/plc4x/plc4go/spi/options"
"github.com/apache/plc4x/plc4go/spi/tracer"
"github.com/apache/plc4x/plc4go/spi/transports"
- "github.com/apache/plc4x/plc4go/spi/utils"
)
func TestDefaultConnectionMetadata_CanBrowse(t *testing.T) {
@@ -545,7 +544,6 @@ func Test_defaultConnection_Close(t *testing.T) {
},
wantAsserter: func(t *testing.T, results <-chan
plc4go.PlcConnectionCloseResult) bool {
timeout := time.NewTimer(2 * time.Second)
- defer utils.CleanupTimer(timeout)
select {
case <-timeout.C:
t.Error("timeout")
@@ -649,7 +647,6 @@ func Test_defaultConnection_ConnectWithContext(t
*testing.T) {
},
wantAsserter: func(t *testing.T, results <-chan
plc4go.PlcConnectionConnectResult) bool {
timeout := time.NewTimer(2 * time.Second)
- defer utils.CleanupTimer(timeout)
select {
case <-timeout.C:
t.Error("timeout")
@@ -894,7 +891,6 @@ func Test_defaultConnection_Ping(t *testing.T) {
},
wantAsserter: func(t *testing.T, results <-chan
plc4go.PlcConnectionPingResult) bool {
timeout := time.NewTimer(2 * time.Second)
- defer utils.CleanupTimer(timeout)
select {
case <-timeout.C:
t.Error("timeout")
@@ -918,7 +914,6 @@ func Test_defaultConnection_Ping(t *testing.T) {
connected: true,
wantAsserter: func(t *testing.T, results <-chan
plc4go.PlcConnectionPingResult) bool {
timeout := time.NewTimer(2 * time.Second)
- defer utils.CleanupTimer(timeout)
select {
case <-timeout.C:
t.Error("timeout")
diff --git a/plc4go/spi/model/DefaultPlcReadRequest_test.go
b/plc4go/spi/model/DefaultPlcReadRequest_test.go
index d9eb62dfc2..f1080fb049 100644
--- a/plc4go/spi/model/DefaultPlcReadRequest_test.go
+++ b/plc4go/spi/model/DefaultPlcReadRequest_test.go
@@ -32,7 +32,6 @@ import (
apiModel "github.com/apache/plc4x/plc4go/pkg/api/model"
"github.com/apache/plc4x/plc4go/spi"
"github.com/apache/plc4x/plc4go/spi/interceptors"
- "github.com/apache/plc4x/plc4go/spi/utils"
)
func TestDefaultPlcReadRequestBuilder_AddTag(t *testing.T) {
@@ -287,9 +286,6 @@ func TestDefaultPlcReadRequest_ExecuteWithContext(t
*testing.T) {
},
wantAsserter: func(t *testing.T, results <-chan
apiModel.PlcReadRequestResult) bool {
timeout := time.NewTimer(100 * time.Millisecond)
- t.Cleanup(func() {
- utils.CleanupTimer(timeout)
- })
select {
case result := <-results:
assert.NoError(t, result.GetErr())
@@ -323,9 +319,6 @@ func TestDefaultPlcReadRequest_ExecuteWithContext(t
*testing.T) {
},
wantAsserter: func(t *testing.T, results <-chan
apiModel.PlcReadRequestResult) bool {
timeout := time.NewTimer(100 * time.Millisecond)
- t.Cleanup(func() {
- utils.CleanupTimer(timeout)
- })
select {
case result := <-results:
assert.Error(t, result.GetErr())
@@ -366,9 +359,6 @@ func TestDefaultPlcReadRequest_ExecuteWithContext(t
*testing.T) {
},
wantAsserter: func(t *testing.T, results <-chan
apiModel.PlcReadRequestResult) bool {
timeout := time.NewTimer(100 * time.Millisecond)
- t.Cleanup(func() {
- utils.CleanupTimer(timeout)
- })
select {
case result := <-results:
assert.Error(t, result.GetErr())
@@ -421,9 +411,6 @@ func TestDefaultPlcReadRequest_ExecuteWithContext(t
*testing.T) {
},
wantAsserter: func(t *testing.T, results <-chan
apiModel.PlcReadRequestResult) bool {
timeout := time.NewTimer(100 * time.Millisecond)
- t.Cleanup(func() {
- utils.CleanupTimer(timeout)
- })
select {
case result := <-results:
assert.NoError(t, result.GetErr())
diff --git a/plc4go/spi/model/DefaultPlcWriteRequest_test.go
b/plc4go/spi/model/DefaultPlcWriteRequest_test.go
index 3a8fde1e3f..983648a1c8 100644
--- a/plc4go/spi/model/DefaultPlcWriteRequest_test.go
+++ b/plc4go/spi/model/DefaultPlcWriteRequest_test.go
@@ -33,7 +33,6 @@ import (
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
"github.com/apache/plc4x/plc4go/spi"
"github.com/apache/plc4x/plc4go/spi/interceptors"
- "github.com/apache/plc4x/plc4go/spi/utils"
)
func TestDefaultPlcWriteRequestBuilder_AddTag(t *testing.T) {
@@ -403,9 +402,6 @@ func TestDefaultPlcWriteRequest_ExecuteWithContext(t
*testing.T) {
},
wantAsserter: func(t *testing.T, results <-chan
apiModel.PlcWriteRequestResult) bool {
timeout := time.NewTimer(100 * time.Millisecond)
- t.Cleanup(func() {
- utils.CleanupTimer(timeout)
- })
select {
case result := <-results:
assert.NoError(t, result.GetErr())
@@ -439,9 +435,6 @@ func TestDefaultPlcWriteRequest_ExecuteWithContext(t
*testing.T) {
},
wantAsserter: func(t *testing.T, results <-chan
apiModel.PlcWriteRequestResult) bool {
timeout := time.NewTimer(100 * time.Millisecond)
- t.Cleanup(func() {
- utils.CleanupTimer(timeout)
- })
select {
case result := <-results:
assert.Error(t, result.GetErr())
@@ -482,9 +475,6 @@ func TestDefaultPlcWriteRequest_ExecuteWithContext(t
*testing.T) {
},
wantAsserter: func(t *testing.T, results <-chan
apiModel.PlcWriteRequestResult) bool {
timeout := time.NewTimer(100 * time.Millisecond)
- t.Cleanup(func() {
- utils.CleanupTimer(timeout)
- })
select {
case result := <-results:
assert.Error(t, result.GetErr())
@@ -537,9 +527,6 @@ func TestDefaultPlcWriteRequest_ExecuteWithContext(t
*testing.T) {
},
wantAsserter: func(t *testing.T, results <-chan
apiModel.PlcWriteRequestResult) bool {
timeout := time.NewTimer(100 * time.Millisecond)
- t.Cleanup(func() {
- utils.CleanupTimer(timeout)
- })
select {
case result := <-results:
assert.NoError(t, result.GetErr())
diff --git a/plc4go/spi/pool/dynamicExecutor.go
b/plc4go/spi/pool/dynamicExecutor.go
index 550873c2b7..d3a77c215d 100644
--- a/plc4go/spi/pool/dynamicExecutor.go
+++ b/plc4go/spi/pool/dynamicExecutor.go
@@ -26,8 +26,6 @@ import (
"time"
"github.com/rs/zerolog"
-
- "github.com/apache/plc4x/plc4go/spi/utils"
)
var upScaleInterval = 100 * time.Millisecond
@@ -111,7 +109,6 @@ func (e *dynamicExecutor) Start() {
func() {
workerLog.Debug().Dur("upScaleInterval",
upScaleInterval).Msg("Sleeping")
timer := time.NewTimer(upScaleInterval)
- defer utils.CleanupTimer(timer)
select {
case <-timer.C:
case <-e.interrupter:
@@ -168,7 +165,6 @@ func (e *dynamicExecutor) Start() {
func() {
workerLog.Debug().Dur("downScaleInterval",
downScaleInterval).Msg("Sleeping for %v")
timer := time.NewTimer(downScaleInterval)
- defer utils.CleanupTimer(timer)
select {
case <-timer.C:
case <-e.interrupter:
diff --git a/plc4go/spi/testutils/DriverTestRunner.go
b/plc4go/spi/testutils/DriverTestRunner.go
index adc3189f1b..d8b396c274 100644
--- a/plc4go/spi/testutils/DriverTestRunner.go
+++ b/plc4go/spi/testutils/DriverTestRunner.go
@@ -106,7 +106,6 @@ func (m DriverTestsuite) Run(t *testing.T, driverManager
plc4go.PlcDriverManager
t.Log("getting a connection")
connectionChan := driverManager.GetConnection(m.driverName +
":test://hurz" + optionsString)
timer := time.NewTimer(DriverTestsuiteConnectTimeout)
- t.Cleanup(func() { utils.CleanupTimer(timer) })
var connectionResult plc4go.PlcConnectionConnectResult
select {
case connectionResult = <-connectionChan:
@@ -120,9 +119,6 @@ func (m DriverTestsuite) Run(t *testing.T, driverManager
plc4go.PlcDriverManager
connection := connectionResult.GetConnection()
t.Cleanup(func() {
timeout := time.NewTimer(30 * time.Second)
- t.Cleanup(func() {
- utils.CleanupTimer(timeout)
- })
select {
case result := <-connection.Close():
assert.NoError(t, result.GetErr())
diff --git a/plc4go/spi/transactions/RequestTransactionManager.go
b/plc4go/spi/transactions/RequestTransactionManager.go
index 1a54158d35..4c1c9c1a87 100644
--- a/plc4go/spi/transactions/RequestTransactionManager.go
+++ b/plc4go/spi/transactions/RequestTransactionManager.go
@@ -37,7 +37,6 @@ import (
"github.com/apache/plc4x/plc4go/pkg/api/config"
"github.com/apache/plc4x/plc4go/spi/options"
"github.com/apache/plc4x/plc4go/spi/pool"
- "github.com/apache/plc4x/plc4go/spi/utils"
)
var sharedExecutorInstance pool.Executor // shared instance
@@ -253,7 +252,6 @@ func (r *requestTransactionManager) CloseGraceful(timeout
time.Duration) error {
r.shutdown.Store(true)
if timeout > 0 {
timer := time.NewTimer(timeout)
- defer utils.CleanupTimer(timer)
gracefulLoop:
for {
r.runningRequestMutex.RLock()
diff --git a/plc4go/spi/utils/Net.go b/plc4go/spi/utils/Net.go
index 8802910db1..4e69357f56 100644
--- a/plc4go/spi/utils/Net.go
+++ b/plc4go/spi/utils/Net.go
@@ -165,7 +165,6 @@ func lockupIpsUsingArp(localLog zerolog.Logger, ctx
context.Context, netInterfac
localLog.Trace().IPAddr("ip",
ip).Msg("Scheduling discovery for IP")
timeout := time.NewTimer(2 * time.Second)
go func(ip net.IP) {
- defer CleanupTimer(timeout)
select {
case <-ctx.Done():
case foundIps <- DuplicateIP(ip):
@@ -253,7 +252,6 @@ func lookupIps(localLog zerolog.Logger, ctx
context.Context, ipnet *net.IPNet, f
timeout := time.NewTimer(2 * time.Second)
go func(ip net.IP) {
defer func() { wg.Done() }()
- defer CleanupTimer(timeout)
select {
case <-ctx.Done():
case foundIps <- ip:
diff --git a/plc4go/spi/utils/common.go b/plc4go/spi/utils/common.go
index c61b1639de..12e96ba1ec 100644
--- a/plc4go/spi/utils/common.go
+++ b/plc4go/spi/utils/common.go
@@ -21,7 +21,6 @@ package utils
import (
"reflect"
- "time"
)
// InlineIf is basically an inline if like construct for golang
@@ -33,21 +32,6 @@ func InlineIf[T any](test bool, a func() T, b func() T) T {
}
}
-// CleanupTimer stops a timer and purges anything left in the channel
-//
-// and is safe to call even if the channel has already been received
-func CleanupTimer(timer *time.Timer) {
- if timer == nil {
- return
- }
- if !timer.Stop() {
- select {
- case <-timer.C:
- default:
- }
- }
-}
-
// ToPtr makes a pointer to T
func ToPtr[T any](v T) *T {
return &v
diff --git a/plc4go/spi/utils/common_test.go b/plc4go/spi/utils/common_test.go
index 0aa7d643f2..6bec17df23 100644
--- a/plc4go/spi/utils/common_test.go
+++ b/plc4go/spi/utils/common_test.go
@@ -21,46 +21,10 @@ package utils
import (
"testing"
- "time"
"github.com/stretchr/testify/assert"
)
-func TestCleanupTimer(t *testing.T) {
- type args struct {
- timer *time.Timer
- }
- tests := []struct {
- name string
- args args
- }{
- {
- name: "nil safety",
- },
- {
- name: "running timer",
- args: args{
- timer: time.NewTimer(100000 * time.Hour),
- },
- },
- {
- name: "completed timer",
- args: args{
- timer: func() *time.Timer {
- timer := time.NewTimer(0)
- timer.Stop()
- return timer
- }(),
- },
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- CleanupTimer(tt.args.timer)
- })
- }
-}
-
func TestInlineIf(t *testing.T) {
type args struct {
test bool
diff --git a/plc4go/tests/drivers/tests/manual_cbus_driver_test.go
b/plc4go/tests/drivers/tests/manual_cbus_driver_test.go
index c6579d14a0..fea70507f3 100644
--- a/plc4go/tests/drivers/tests/manual_cbus_driver_test.go
+++ b/plc4go/tests/drivers/tests/manual_cbus_driver_test.go
@@ -33,7 +33,6 @@ import (
"github.com/apache/plc4x/plc4go/pkg/api/transports"
"github.com/apache/plc4x/plc4go/spi/options/converter"
"github.com/apache/plc4x/plc4go/spi/testutils"
- "github.com/apache/plc4x/plc4go/spi/utils"
)
func TestManualCBusDriverMixed(t *testing.T) {
@@ -85,7 +84,6 @@ func TestManualCBusDriverMixed(t *testing.T) {
require.NoError(t, err)
subscriptionRequest.Execute()
timeout := time.NewTimer(30 * time.Second)
- defer utils.CleanupTimer(timeout)
// We expect couple monitors
mmiCount := 0
salCount := 0