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 b19149793d6bf91deccf658aa9c61da4e2c87fe2 Author: Sebastian Rühl <[email protected]> AuthorDate: Mon Nov 10 16:25:39 2025 +0100 test(plc4go): fix stuck tests --- plc4go/spi/pool/dynamicExecutor_test.go | 58 ++++++++++------------ plc4go/spi/pool/executor_test.go | 46 +++++++---------- plc4go/spi/pool/worker_test.go | 26 +++++++--- .../transactions/RequestTransactionManager_test.go | 43 ++++++++-------- 4 files changed, 86 insertions(+), 87 deletions(-) diff --git a/plc4go/spi/pool/dynamicExecutor_test.go b/plc4go/spi/pool/dynamicExecutor_test.go index 0b66250570..f9534da1c4 100644 --- a/plc4go/spi/pool/dynamicExecutor_test.go +++ b/plc4go/spi/pool/dynamicExecutor_test.go @@ -36,30 +36,21 @@ func Test_newDynamicExecutor(t *testing.T) { log zerolog.Logger } tests := []struct { - name string - args args - want *dynamicExecutor - manipulator func(t *testing.T, want *dynamicExecutor, got *dynamicExecutor) + name string + args args + wantAssert func(*testing.T, *dynamicExecutor) bool }{ { name: "just create it", - want: &dynamicExecutor{ - executor: newExecutor(0, 0, zerolog.Logger{}), - }, - manipulator: func(t *testing.T, want *dynamicExecutor, got *dynamicExecutor) { - assert.NotNil(t, got.workItems) - want.workItems = got.workItems + wantAssert: func(t *testing.T, d *dynamicExecutor) bool { + return assert.NotNil(t, d.executor) }, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got := newDynamicExecutor(tt.args.queueDepth, tt.args.maxNumberOfWorkers, tt.args.log) - want := tt.want - if tt.manipulator != nil { - tt.manipulator(t, want, got) - } - assert.Equalf(t, want, got, "newDynamicExecutor(%v, %v, %v)", tt.args.queueDepth, tt.args.maxNumberOfWorkers, tt.args.log) + assert.Truef(t, tt.wantAssert(t, got), "newDynamicExecutor(%v, %v, %v)", tt.args.queueDepth, tt.args.maxNumberOfWorkers, tt.args.log) }) } } @@ -82,6 +73,8 @@ func Test_dynamicExecutor_Start(t *testing.T) { workItems: make(chan workItem, 1), worker: make([]*worker, 0), traceWorkers: true, + ctxCancel: func() {}, + ctx: t.Context(), }, maxNumberOfWorkers: 100, }, @@ -97,6 +90,8 @@ func Test_dynamicExecutor_Start(t *testing.T) { workItems: make(chan workItem, 1), worker: make([]*worker, 0), traceWorkers: true, + ctxCancel: func() {}, + ctx: t.Context(), }, maxNumberOfWorkers: 100, }, @@ -236,24 +231,21 @@ func Test_dynamicExecutor_String(t *testing.T) { maxNumberOfWorkers: 3, }, want: ` -╔═dynamicExecutor══════════════════════════════════════════════════════════════════════════════════════════╗ -║╔═executor═══════════════════════════════════════════════════════════════════════════════════════════════╗║ -║║╔═running╗╔═shutdown╗ ║║ -║║║b0 false║║b0 false ║ ║║ -║║╚════════╝╚═════════╝ ║║ -║║╔═worker/value/worker══════════════════════════════════════════════════════════════════════════════════╗║║ -║║║╔═id═════════════════╗╔═lastReceived════════════════╗╔═running╗╔═shutdown╗╔═interrupted╗╔═interrupter╗║║║ -║║║║0x0000000000000000 0║║0001-01-01 00:00:00 +0000 UTC║║b0 false║║b0 false ║║ b0 false ║║0 element(s)║║║║ -║║║╚════════════════════╝╚═════════════════════════════╝╚════════╝╚═════════╝╚════════════╝╚════════════╝║║║ -║║╚══════════════════════════════════════════════════════════════════════════════════════════════════════╝║║ -║║╔═workItems══╗╔═traceWorkers╗ ║║ -║║║0 element(s)║║ b0 false ║ ║║ -║║╚════════════╝╚═════════════╝ ║║ -║╚════════════════════════════════════════════════════════════════════════════════════════════════════════╝║ -║╔═maxNumberOfWorkers═╗╔═currentNumberOfWorkers╗╔═interrupter╗ ║ -║║0x0000000000000003 3║║ 0x00000000 0 ║║0 element(s)║ ║ -║╚════════════════════╝╚═══════════════════════╝╚════════════╝ ║ -╚══════════════════════════════════════════════════════════════════════════════════════════════════════════╝`[1:], +╔═dynamicExecutor═════════════════════════════════════════════════════════════════════════════════════════╗ +║╔═executor══════════════════════════════════════════════════════════════════════════════════════════════╗║ +║║╔═running╗╔═shutdown╗╔═worker/value/worker════════════════════════════════════════════════════════════╗║║ +║║║b0 false║║b0 false ║║╔═lastReceived════════════════╗╔═running╗╔═shutdown╗╔═interrupted╗╔═interrupter╗║║║ +║║╚════════╝╚═════════╝║║0001-01-01 00:00:00 +0000 UTC║║b0 false║║b0 false ║║ b0 false ║║0 element(s)║║║║ +║║ ║╚═════════════════════════════╝╚════════╝╚═════════╝╚════════════╝╚════════════╝║║║ +║║ ╚════════════════════════════════════════════════════════════════════════════════╝║║ +║║╔═workerNumber╗╔═workItems══╗╔═traceWorkers╗ ║║ +║║║0x00000000 0 ║║0 element(s)║║ b0 false ║ ║║ +║║╚═════════════╝╚════════════╝╚═════════════╝ ║║ +║╚═══════════════════════════════════════════════════════════════════════════════════════════════════════╝║ +║╔═maxNumberOfWorkers═╗╔═currentNumberOfWorkers╗╔═interrupter╗ ║ +║║0x0000000000000003 3║║ 0x00000000 0 ║║0 element(s)║ ║ +║╚════════════════════╝╚═══════════════════════╝╚════════════╝ ║ +╚═════════════════════════════════════════════════════════════════════════════════════════════════════════╝`[1:], }, } for _, tt := range tests { diff --git a/plc4go/spi/pool/executor_test.go b/plc4go/spi/pool/executor_test.go index b96fd07957..047dafa394 100644 --- a/plc4go/spi/pool/executor_test.go +++ b/plc4go/spi/pool/executor_test.go @@ -38,30 +38,21 @@ func Test_newExecutor(t *testing.T) { log zerolog.Logger } tests := []struct { - name string - args args - want *executor - manipulator func(t *testing.T, want *executor, got *executor) + name string + args args + wantAssert func(*testing.T, *executor) bool }{ { name: "just create it", - want: &executor{ - worker: []*worker{}, - }, - manipulator: func(t *testing.T, want *executor, got *executor) { - assert.NotNil(t, got.workItems) - want.workItems = got.workItems + wantAssert: func(t *testing.T, got *executor) bool { + return assert.NotNil(t, got) }, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got := newExecutor(tt.args.queueDepth, tt.args.numberOfInitialWorkers, tt.args.log) - want := tt.want - if tt.manipulator != nil { - tt.manipulator(t, want, got) - } - assert.Equalf(t, want, got, "newExecutor(%v, %v, %v)", tt.args.queueDepth, tt.args.numberOfInitialWorkers, tt.args.log) + assert.Truef(t, tt.wantAssert(t, got), "newExecutor(%v, %v, %v)", tt.args.queueDepth, tt.args.numberOfInitialWorkers, tt.args.log) }) } } @@ -220,6 +211,8 @@ func Test_executor_Stop(t *testing.T) { worker: tt.fields.worker, workItems: tt.fields.queue, traceWorkers: tt.fields.traceWorkers, + ctxCancel: func() {}, + ctx: t.Context(), } e.Stop() }) @@ -473,19 +466,16 @@ func Test_executor_String(t *testing.T) { traceWorkers: true, }, want: ` -╔═executor═════════════════════════════════════════════════════════════════════════════════════════════════════════════╗ -║╔═running╗╔═shutdown╗ ║ -║║b1 true ║║ b1 true ║ ║ -║╚════════╝╚═════════╝ ║ -║╔═worker/value/worker══════════════════════════════════════════════════════════════════════════════════╗╔═workItems══╗║ -║║╔═id═════════════════╗╔═lastReceived════════════════╗╔═running╗╔═shutdown╗╔═interrupted╗╔═interrupter╗║║0 element(s)║║ -║║║0x0000000000000001 1║║0001-01-01 00:00:00 +0000 UTC║║b0 false║║b0 false ║║ b0 false ║║0 element(s)║║╚════════════╝║ -║║╚════════════════════╝╚═════════════════════════════╝╚════════╝╚═════════╝╚════════════╝╚════════════╝║ ║ -║╚══════════════════════════════════════════════════════════════════════════════════════════════════════╝ ║ -║╔═traceWorkers╗ ║ -║║ b1 true ║ ║ -║╚═════════════╝ ║ -╚══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝`[1:], +╔═executor═══════════════════════════════════════════════════════════════════════════════════════════════════╗ +║╔═running╗╔═shutdown╗╔═worker/value/worker═════════════════════════════════════════════════════════════════╗║ +║║b1 true ║║ b1 true ║║╔═id╗╔═lastReceived════════════════╗╔═running╗╔═shutdown╗╔═interrupted╗╔═interrupter╗║║ +║╚════════╝╚═════════╝║║ 1 ║║0001-01-01 00:00:00 +0000 UTC║║b0 false║║b0 false ║║ b0 false ║║0 element(s)║║║ +║ ║╚═══╝╚═════════════════════════════╝╚════════╝╚═════════╝╚════════════╝╚════════════╝║║ +║ ╚═════════════════════════════════════════════════════════════════════════════════════╝║ +║╔═workerNumber╗╔═workItems══╗╔═traceWorkers╗ ║ +║║0x00000000 0 ║║0 element(s)║║ b1 true ║ ║ +║╚═════════════╝╚════════════╝╚═════════════╝ ║ +╚════════════════════════════════════════════════════════════════════════════════════════════════════════════╝`[1:], }, } for _, tt := range tests { diff --git a/plc4go/spi/pool/worker_test.go b/plc4go/spi/pool/worker_test.go index a3abd9dfef..3833673f73 100644 --- a/plc4go/spi/pool/worker_test.go +++ b/plc4go/spi/pool/worker_test.go @@ -171,16 +171,22 @@ func Test_worker_stop(t *testing.T) { e := &executor{ workItems: make(chan workItem), traceWorkers: true, + ctx: t.Context(), + ctxCancel: func() {}, } var wg sync.WaitGroup t.Cleanup(wg.Wait) wg.Go(func() { - e.workItems <- workItem{ + select { + case e.workItems <- workItem{ workItemId: 0, runnable: func(context.Context) { // No-op }, completionFuture: &future{}, + }: + case <-t.Context().Done(): + return } }) return e @@ -231,6 +237,8 @@ func Test_worker_work(t *testing.T) { e := &executor{ workItems: make(chan workItem), traceWorkers: true, + ctx: t.Context(), + ctxCancel: func() {}, } var wg sync.WaitGroup t.Cleanup(wg.Wait) @@ -267,6 +275,8 @@ func Test_worker_work(t *testing.T) { e := &executor{ workItems: make(chan workItem), traceWorkers: true, + ctx: t.Context(), + ctxCancel: func() {}, } var wg sync.WaitGroup t.Cleanup(wg.Wait) @@ -302,6 +312,8 @@ func Test_worker_work(t *testing.T) { e := &executor{ workItems: make(chan workItem), traceWorkers: true, + ctx: t.Context(), + ctxCancel: func() {}, } return e }(), @@ -327,6 +339,8 @@ func Test_worker_work(t *testing.T) { e := &executor{ workItems: make(chan workItem), traceWorkers: true, + ctx: t.Context(), + ctxCancel: func() {}, } var wg sync.WaitGroup t.Cleanup(wg.Wait) @@ -396,11 +410,11 @@ func Test_worker_String(t *testing.T) { { name: "string it", want: ` -╔═worker═══════════════════════════════════════════════════════════════════════════════════════════════╗ -║╔═id═════════════════╗╔═lastReceived════════════════╗╔═running╗╔═shutdown╗╔═interrupted╗╔═interrupter╗║ -║║0x0000000000000000 0║║0001-01-01 00:00:00 +0000 UTC║║b0 false║║b0 false ║║ b0 false ║║0 element(s)║║ -║╚════════════════════╝╚═════════════════════════════╝╚════════╝╚═════════╝╚════════════╝╚════════════╝║ -╚══════════════════════════════════════════════════════════════════════════════════════════════════════╝`[1:], +╔═worker═════════════════════════════════════════════════════════════════════════╗ +║╔═lastReceived════════════════╗╔═running╗╔═shutdown╗╔═interrupted╗╔═interrupter╗║ +║║0001-01-01 00:00:00 +0000 UTC║║b0 false║║b0 false ║║ b0 false ║║0 element(s)║║ +║╚═════════════════════════════╝╚════════╝╚═════════╝╚════════════╝╚════════════╝║ +╚════════════════════════════════════════════════════════════════════════════════╝`[1:], }, } for _, tt := range tests { diff --git a/plc4go/spi/transactions/RequestTransactionManager_test.go b/plc4go/spi/transactions/RequestTransactionManager_test.go index 8dc361bd9e..51a4b7cbc1 100644 --- a/plc4go/spi/transactions/RequestTransactionManager_test.go +++ b/plc4go/spi/transactions/RequestTransactionManager_test.go @@ -664,26 +664,29 @@ func Test_requestTransactionManager_String(t *testing.T) { traceTransactionManagerTransactions: true, }, want: ` -╔═requestTransactionManager══════════════════════════════════════════════════════════════════════════════════════════╗ -║╔═runningRequests/value/requestTransaction╗╔═numberOfConcurrentRequests╗╔═currentTransactionId╗ ║ -║║ ╔═transactionId╗╔═completed╗ ║║ 0x0000000000000003 3 ║║ 0x00000004 4 ║ ║ -║║ ║ 0x00000002 2 ║║ b0 false ║ ║╚═══════════════════════════╝╚═════════════════════╝ ║ -║║ ╚══════════════╝╚══════════╝ ║ ║ -║╚═════════════════════════════════════════╝ ║ -║╔═executor/executor════════════════════════════════════════════════════════════════════════════════════════════════╗║ -║║╔═running╗╔═shutdown╗╔═worker/value/worker═══════════════════════════════════════════════════════════════════════╗║║ -║║║b0 false║║b0 false ║║╔═id══════╗╔═lastReceived════════════════╗╔═running╗╔═shutdown╗╔═interrupted╗╔═interrupter╗║║║ -║║╚════════╝╚═════════╝║║-worker-0║║0001-01-01 00:00:00 +0000 UTC║║b0 false║║b0 false ║║ b0 false ║║0 element(s)║║║║ -║║ ║╚═════════╝╚═════════════════════════════╝╚════════╝╚═════════╝╚════════════╝╚════════════╝║║║ -║║ ╚═══════════════════════════════════════════════════════════════════════════════════════════╝║║ -║║╔═workerNumber╗╔═workItems══╗╔═traceWorkers╗╔═ctx═════════════════════════╗╔═ctxCancel╗ ║║ -║║║0x00000000 0 ║║0 element(s)║║ b0 false ║║context.Background.WithCancel║║ 0xc4760 ║ ║║ -║║╚═════════════╝╚════════════╝╚═════════════╝╚═════════════════════════════╝╚══════════╝ ║║ -║╚══════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝║ -║╔═shutdown╗╔═traceTransactionManagerTransactions╗ ║ -║║b0 false ║║ b1 true ║ ║ -║╚═════════╝╚════════════════════════════════════╝ ║ -╚════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝`[1:], +╔═requestTransactionManager═══════════════════════════════════════════════════════════════════════════════════════════╗ +║╔═runningRequests/value/requestTransaction╗╔═numberOfConcurrentRequests╗╔═currentTransactionId╗ ║ +║║ ╔═transactionId╗╔═completed╗ ║║ 0x0000000000000003 3 ║║ 0x00000004 4 ║ ║ +║║ ║ 0x00000002 2 ║║ b0 false ║ ║╚═══════════════════════════╝╚═════════════════════╝ ║ +║║ ╚══════════════╝╚══════════╝ ║ ║ +║╚═════════════════════════════════════════╝ ║ +║╔═executor/executor══════════════════════════════════════════════════════════════════════════════════════╗╔═shutdown╗║ +║║╔═name══════╗╔═running╗╔═shutdown╗ ║║b0 false ║║ +║║║executor-10║║b0 false║║b0 false ║ ║╚═════════╝║ +║║╚═══════════╝╚════════╝╚═════════╝ ║ ║ +║║╔═worker/value/worker══════════════════════════════════════════════════════════════════════════════════╗║ ║ +║║║╔═id═════════════════╗╔═lastReceived════════════════╗╔═running╗╔═shutdown╗╔═interrupted╗╔═interrupter╗║║ ║ +║║║║executor-10-worker-0║║0001-01-01 00:00:00 +0000 UTC║║b0 false║║b0 false ║║ b0 false ║║0 element(s)║║║ ║ +║║║╚════════════════════╝╚═════════════════════════════╝╚════════╝╚═════════╝╚════════════╝╚════════════╝║║ ║ +║║╚══════════════════════════════════════════════════════════════════════════════════════════════════════╝║ ║ +║║╔═workerNumber╗╔═workItems══╗╔═traceWorkers╗╔═ctx═════════════════════════╗╔═ctxCancel╗ ║ ║ +║║║0x00000000 0 ║║0 element(s)║║ b0 false ║║context.Background.WithCancel║║ 0xc4760 ║ ║ ║ +║║╚═════════════╝╚════════════╝╚═════════════╝╚═════════════════════════════╝╚══════════╝ ║ ║ +║╚════════════════════════════════════════════════════════════════════════════════════════════════════════╝ ║ +║╔═traceTransactionManagerTransactions╗ ║ +║║ b1 true ║ ║ +║╚════════════════════════════════════╝ ║ +╚═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝`[1:], }, } for _, tt := range tests {
