Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
test(mcp): stabilize concurrent policy updates on SQLite
wizardchenac4dd59712b6
diff --git a/internal/application/repository/mcp_tool_approval_repository_test.go b/internal/application/repository/mcp_tool_approval_repository_test.goindex ae8b2eb2d..fd1693371 100644--- a/internal/application/repository/mcp_tool_approval_repository_test.go+++ b/internal/application/repository/mcp_tool_approval_repository_test.go@@ -2,12 +2,12 @@ package repositoryimport ("context"- "fmt""sync""testing""github.com/Tencent/WeKnora/internal/types""github.com/Tencent/WeKnora/internal/types/interfaces"+ "github.com/google/uuid""github.com/stretchr/testify/require""gorm.io/driver/sqlite""gorm.io/gorm"@@ -15,9 +15,15 @@ import (func newMCPToolApprovalTestRepo(t *testing.T) interfaces.MCPToolApprovalRepository {t.Helper()- dsn := fmt.Sprintf("file:%s?mode=memory&cache=shared&_busy_timeout=5000", t.Name())+ dsn := "file:" + uuid.NewString() + "?mode=memory&cache=shared&_busy_timeout=5000"db, err := gorm.Open(sqlite.Open(dsn), &gorm.Config{})require.NoError(t, err)+ sqlDB, err := db.DB()+ require.NoError(t, err)+ t.Cleanup(func() { require.NoError(t, sqlDB.Close()) })+ // Match the production SQLite pool: concurrent callers share one connection.+ // A busy timeout cannot resolve shared-cache SQLITE_LOCKED table conflicts.+ sqlDB.SetMaxOpenConns(1)require.NoError(t, db.AutoMigrate(&types.MCPToolApproval{}))return NewMCPToolApprovalRepository(db)}@@ -98,15 +104,19 @@ func TestMCPToolApprovalConcurrentColumnPatches(t *testing.T) {var wg sync.WaitGrouperrs := make(chan error, 2)+ start := make(chan struct{})wg.Add(2)go func() {defer wg.Done()+ <-starterrs <- repo.UpsertPolicy(ctx, 1, "svc", "tool", types.MCPToolPolicyPatch{Enabled: boolPtr(false)})}()go func() {defer wg.Done()+ <-starterrs <- repo.UpsertPolicy(ctx, 1, "svc", "tool", types.MCPToolPolicyPatch{RequireApproval: boolPtr(true)})}()+ close(start)wg.Wait()close(errs)for err := range errs {