feat(configuration): update asynq concurrency settings and enhance FAQ handling
- Increased the default worker pool size for the asynq server from 16 to 32 to improve performance during concurrent uploads. - Updated the .env.example and docker-compose.yml files to reflect the new default concurrency setting. - Enhanced the handling of FAQ entries in the tool results, ensuring distinct identification through standard questions, improving user experience and clarity in the output. - Refactored related components to utilize the new FAQ attributes, ensuring consistent display and interaction across the application.
This commit is contained in:
@@ -2,11 +2,13 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/config"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/Tencent/WeKnora/internal/types/interfaces"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"gorm.io/driver/sqlite"
|
||||
@@ -95,14 +97,41 @@ func insertSpan(t *testing.T, db *gorm.DB, kid string, attempt int, spanID, stat
|
||||
).Error)
|
||||
}
|
||||
|
||||
// fakeTaskInspector is a controllable TaskInspector for the housekeeping
|
||||
// suite. queued maps knowledge_id → "still has a queued task"; err forces
|
||||
// the probe to fail so the fail-safe branch can be exercised.
|
||||
type fakeTaskInspector struct {
|
||||
queued map[string]bool
|
||||
err error
|
||||
}
|
||||
|
||||
func (f fakeTaskInspector) CancelTasksForKnowledge(
|
||||
_ context.Context, _ string,
|
||||
) (int, int, error) {
|
||||
return 0, 0, nil
|
||||
}
|
||||
|
||||
func (f fakeTaskInspector) HasQueuedTasksForKnowledge(
|
||||
_ context.Context, knowledgeID string,
|
||||
) (bool, error) {
|
||||
if f.err != nil {
|
||||
return false, f.err
|
||||
}
|
||||
return f.queued[knowledgeID], nil
|
||||
}
|
||||
|
||||
func newHousekeepingSvcForTest(db *gorm.DB) *HousekeepingService {
|
||||
return newHousekeepingSvcWithInspector(db, fakeTaskInspector{})
|
||||
}
|
||||
|
||||
func newHousekeepingSvcWithInspector(db *gorm.DB, inspector interfaces.TaskInspector) *HousekeepingService {
|
||||
cfg := &config.Config{KnowledgeBase: &config.KnowledgeBaseConfig{
|
||||
// 1h floor + 10min buffer = 70min cutoff. Tight enough to keep
|
||||
// the test's relative timestamps in seconds; the production
|
||||
// default of 2h+10min is just a constant scale factor.
|
||||
DocumentProcessTimeout: 1 * time.Hour,
|
||||
}}
|
||||
return NewHousekeepingService(db, cfg)
|
||||
return NewHousekeepingService(db, cfg, inspector)
|
||||
}
|
||||
|
||||
// TestHousekeeping_RecoversAbandoned exercises the happy path: a
|
||||
@@ -170,6 +199,52 @@ func TestHousekeeping_NoFalseKill_StaleSpanRecovers(t *testing.T) {
|
||||
"genuinely stuck knowledge (knowledge AND spans both stale) must still be recovered")
|
||||
}
|
||||
|
||||
// TestHousekeeping_NoFalseKill_TasksStillQueued is the regression test
|
||||
// for the backpressure case: a finalizing row whose span heartbeat has
|
||||
// gone stale (enrichment subtasks fanned out but no worker has picked
|
||||
// them up yet) must NOT be killed while its tasks are still queued.
|
||||
func TestHousekeeping_NoFalseKill_TasksStillQueued(t *testing.T) {
|
||||
db := setupHousekeepingDB(t)
|
||||
svc := newHousekeepingSvcWithInspector(db, fakeTaskInspector{
|
||||
queued: map[string]bool{"kid-backlogged": true},
|
||||
})
|
||||
stale := time.Now().Add(-3 * time.Hour)
|
||||
// finalizing + stale knowledge + stale span: span-only heuristics
|
||||
// would flag this as stuck, but the queue still holds its subtasks.
|
||||
insertKnowledge(t, db, "kid-backlogged", types.ParseStatusFinalizing, stale)
|
||||
insertSpan(t, db, "kid-backlogged", 1, "post-1", types.SpanStatusRunning, stale)
|
||||
|
||||
svc.runSweep(context.Background())
|
||||
|
||||
var status string
|
||||
require.NoError(t, db.Raw(
|
||||
`SELECT parse_status FROM knowledges WHERE id = ?`, "kid-backlogged",
|
||||
).Row().Scan(&status))
|
||||
assert.Equal(t, types.ParseStatusFinalizing, status,
|
||||
"finalizing row with tasks still queued must NOT be flipped to failed")
|
||||
}
|
||||
|
||||
// TestHousekeeping_QueueProbeError_FailsSafe confirms the fail-safe
|
||||
// direction: when the queue probe errors we still recover the row rather
|
||||
// than leaving it stranded forever.
|
||||
func TestHousekeeping_QueueProbeError_FailsSafe(t *testing.T) {
|
||||
db := setupHousekeepingDB(t)
|
||||
svc := newHousekeepingSvcWithInspector(db, fakeTaskInspector{
|
||||
err: errors.New("redis unavailable"),
|
||||
})
|
||||
stale := time.Now().Add(-3 * time.Hour)
|
||||
insertKnowledge(t, db, "kid-probeerr", types.ParseStatusProcessing, stale)
|
||||
|
||||
svc.runSweep(context.Background())
|
||||
|
||||
var status string
|
||||
require.NoError(t, db.Raw(
|
||||
`SELECT parse_status FROM knowledges WHERE id = ?`, "kid-probeerr",
|
||||
).Row().Scan(&status))
|
||||
assert.Equal(t, types.ParseStatusFailed, status,
|
||||
"queue probe error must fail safe and still recover the stuck row")
|
||||
}
|
||||
|
||||
// TestHousekeeping_PreservesRecentlyTouched: any knowledge whose
|
||||
// updated_at is within the cutoff is left alone — that's the cheap
|
||||
// fast path that doesn't even consult the spans table.
|
||||
|
||||
Reference in New Issue
Block a user