mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
outlet/kafka: fix race in tests
Some checks failed
CI / 🤖 Check dependabot status (push) Has been cancelled
CI / 🐧 Test on Linux (${{ github.ref_type == 'tag' }}, misc) (push) Has been cancelled
CI / 🐧 Test on Linux (coverage) (push) Has been cancelled
CI / 🐧 Test on Linux (regular) (push) Has been cancelled
CI / ❄️ Build on Nix (push) Has been cancelled
CI / 🍏 Build and test on macOS (push) Has been cancelled
CI / 🧪 End-to-end testing (push) Has been cancelled
CI / 🔍 Upload code coverage (push) Has been cancelled
CI / 🔬 Test only Go (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 20) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 22) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 24) (push) Has been cancelled
CI / ⚖️ Check licenses (push) Has been cancelled
CI / 🐋 Build Docker images (push) Has been cancelled
CI / 🐋 Tag Docker images (push) Has been cancelled
CI / 🚀 Publish release (push) Has been cancelled
Some checks failed
CI / 🤖 Check dependabot status (push) Has been cancelled
CI / 🐧 Test on Linux (${{ github.ref_type == 'tag' }}, misc) (push) Has been cancelled
CI / 🐧 Test on Linux (coverage) (push) Has been cancelled
CI / 🐧 Test on Linux (regular) (push) Has been cancelled
CI / ❄️ Build on Nix (push) Has been cancelled
CI / 🍏 Build and test on macOS (push) Has been cancelled
CI / 🧪 End-to-end testing (push) Has been cancelled
CI / 🔍 Upload code coverage (push) Has been cancelled
CI / 🔬 Test only Go (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 20) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 22) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 24) (push) Has been cancelled
CI / ⚖️ Check licenses (push) Has been cancelled
CI / 🐋 Build Docker images (push) Has been cancelled
CI / 🐋 Tag Docker images (push) Has been cancelled
CI / 🚀 Publish release (push) Has been cancelled
This was introduced in the fix introduced in 7f5950f89c.
This commit is contained in:
@@ -5,6 +5,7 @@ package kafka
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -17,7 +18,7 @@ func TestMock(t *testing.T) {
|
||||
got := []string{}
|
||||
expected := []string{"hello1", "hello2", "hello3"}
|
||||
gotAll := make(chan bool)
|
||||
shutdownCalled := false
|
||||
var shutdownCalled atomic.Bool
|
||||
callback := func(_ context.Context, message []byte) error {
|
||||
got = append(got, string(message))
|
||||
if len(got) == len(expected) {
|
||||
@@ -27,7 +28,7 @@ func TestMock(t *testing.T) {
|
||||
}
|
||||
c.StartWorkers(
|
||||
func(int, chan<- ScaleRequest) (ReceiveFunc, ShutdownFunc) {
|
||||
return callback, func() { shutdownCalled = true }
|
||||
return callback, func() { shutdownCalled.Store(true) }
|
||||
},
|
||||
)
|
||||
|
||||
@@ -47,7 +48,7 @@ func TestMock(t *testing.T) {
|
||||
|
||||
c.Stop()
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
if !shutdownCalled {
|
||||
if !shutdownCalled.Load() {
|
||||
t.Error("Stop() should have triggered shutdown function")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user