mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-14 12:16:54 +00:00
fix(test): resolve data race in TTS concurrent test mock
Add stateless flag to mockTTSProvider to skip capturing opts during concurrent tests. Prevents race on capturedOpts field.
This commit is contained in:
1 parent
a65eaa457a
commit
a050079ade
2 files changed
+7
-4
No files matched your search
@@ -25,12 +25,15 @@ type mockTTSProvider struct {
|
||||
result *audio.SynthResult
|
||||
err error
|
||||
block bool // if true, blocks until ctx is cancelled (timeout test)
|
||||
stateless bool // if true, don't capture opts (for concurrent tests)
|
||||
}
|
||||
|
||||
func (m *mockTTSProvider) Name() string { return m.name }
|
||||
|
||||
func (m *mockTTSProvider) Synthesize(ctx context.Context, text string, opts audio.TTSOptions) (*audio.SynthResult, error) {
|
||||
m.capturedOpts = opts
|
||||
if !m.stateless {
|
||||
m.capturedOpts = opts
|
||||
}
|
||||
if m.block {
|
||||
<-ctx.Done()
|
||||
return nil, ctx.Err()
|
||||
|
||||
@@ -66,9 +66,9 @@ func TestTTSHandler_UpdateManager_SwapsProvider(t *testing.T) {
|
||||
func TestTTSHandler_UpdateManager_ConcurrentSafe(t *testing.T) {
|
||||
setupTestToken(t, "") // dev mode
|
||||
|
||||
// Use stateless mock — each provider is separate instance
|
||||
// Use stateless mock to avoid race on capturedOpts
|
||||
mgr := audio.NewManager(audio.ManagerConfig{Primary: "mock"})
|
||||
mgr.RegisterTTS(&mockTTSProvider{name: "mock"})
|
||||
mgr.RegisterTTS(&mockTTSProvider{name: "mock", stateless: true})
|
||||
|
||||
h := NewTTSHandler(mgr)
|
||||
mux := http.NewServeMux()
|
||||
@@ -96,7 +96,7 @@ func TestTTSHandler_UpdateManager_ConcurrentSafe(t *testing.T) {
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
newMgr := audio.NewManager(audio.ManagerConfig{Primary: "mock-new"})
|
||||
newMgr.RegisterTTS(&mockTTSProvider{name: "mock-new"})
|
||||
newMgr.RegisterTTS(&mockTTSProvider{name: "mock-new", stateless: true})
|
||||
h.UpdateManager(newMgr)
|
||||
}()
|
||||
|
||||
|
||||
Reference in new issue
Block a user