From 754b1ad88bb387d56557d4045437a48dc7308526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=AC=E6=98=8E?= <83812544+Ed1s0nZ@users.noreply.github.com> Date: Mon, 6 Jul 2026 14:17:49 +0800 Subject: [PATCH] Add files via upload --- .../multiagent/mcp_execution_binder_test.go | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/internal/multiagent/mcp_execution_binder_test.go b/internal/multiagent/mcp_execution_binder_test.go index 47973194..e2f142fd 100644 --- a/internal/multiagent/mcp_execution_binder_test.go +++ b/internal/multiagent/mcp_execution_binder_test.go @@ -1,6 +1,10 @@ package multiagent -import "testing" +import ( + "fmt" + "sync" + "testing" +) func TestMCPExecutionBinder(t *testing.T) { b := NewMCPExecutionBinder() @@ -12,3 +16,28 @@ func TestMCPExecutionBinder(t *testing.T) { t.Fatalf("expected empty, got %q", got) } } + +// TestMCPExecutionBinder_ConcurrentBind 回归并行 tool 回调不得 concurrent map panic。 +func TestMCPExecutionBinder_ConcurrentBind(t *testing.T) { + b := NewMCPExecutionBinder() + const workers = 64 + var wg sync.WaitGroup + wg.Add(workers * 2) + for i := 0; i < workers; i++ { + i := i + toolCallID := fmt.Sprintf("call-%d", i) + execID := fmt.Sprintf("exec-%d", i) + go func() { + defer wg.Done() + b.Bind(toolCallID, execID) + }() + go func() { + defer wg.Done() + _ = b.ExecutionID(toolCallID) + }() + } + wg.Wait() + if got := b.ExecutionID("call-0"); got != "exec-0" { + t.Fatalf("expected exec-0, got %q", got) + } +}