Enhance Cleanup Logic in Auth Integration Tests
- Updated the cleanup process in `cleanupAuthCollections` to include a waiting mechanism for Qdrant to fully process deletions, improving reliability of test setups. - Removed unnecessary sleep calls and added logging to warn if collections still exist after cleanup, ensuring better visibility during test execution. - Refactored comments for clarity regarding the cleanup process in both `TestAuthSearchSetup` and `ensureAuthTestData` functions.
This commit is contained in:
parent
47290d439d
commit
a966ad83ee
1 changed files with 20 additions and 8 deletions
|
|
@ -60,10 +60,9 @@ func TestAuthSearchSetup(t *testing.T) {
|
|||
return
|
||||
}
|
||||
|
||||
// Cleanup existing
|
||||
// Cleanup existing (includes waiting for deletion to complete)
|
||||
t.Log("Cleaning up existing collections...")
|
||||
cleanupAuthCollections(ctx, t)
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
// Create Team1 collection (owned by UserA, Team1)
|
||||
t.Log("Creating Team1 collection...")
|
||||
|
|
@ -461,10 +460,9 @@ func ensureAuthTestData(t *testing.T) {
|
|||
|
||||
// createAuthTestData creates the test collections and documents
|
||||
func createAuthTestData(t *testing.T, ctx context.Context) {
|
||||
// Cleanup existing
|
||||
// Cleanup existing (includes waiting for deletion to complete)
|
||||
t.Log("Cleaning up existing collections...")
|
||||
cleanupAuthCollections(ctx, t)
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
// Create Team1 collection (owned by UserA, Team1)
|
||||
t.Log("Creating Team1 collection...")
|
||||
|
|
@ -529,6 +527,24 @@ func cleanupAuthCollections(ctx context.Context, t *testing.T) {
|
|||
t.Logf(" Removed: %s", id)
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for Qdrant to fully process deletions
|
||||
// This is necessary because Qdrant may take time to propagate deletions
|
||||
maxRetries := 10
|
||||
for retry := 0; retry < maxRetries; retry++ {
|
||||
allGone := true
|
||||
for _, id := range collections {
|
||||
if exists, err := kb.API.CollectionExists(ctx, id); err == nil && exists.Exists {
|
||||
allGone = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if allGone {
|
||||
return
|
||||
}
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
t.Log(" Warning: Some collections may still exist after cleanup")
|
||||
}
|
||||
|
||||
func createAuthCollection(ctx context.Context, t *testing.T, id, userID, teamID string, public bool, share string) {
|
||||
|
|
@ -597,10 +613,6 @@ func sanitizeForID(s string) string {
|
|||
return result
|
||||
}
|
||||
|
||||
func executeKBSearch(t *testing.T, collectionID, query string, metadata map[string]interface{}) *searchTypes.Result {
|
||||
return executeKBSearchOnCollections(t, []string{collectionID}, query)
|
||||
}
|
||||
|
||||
func executeKBSearchOnCollections(t *testing.T, collections []string, query string) *searchTypes.Result {
|
||||
if len(collections) == 0 {
|
||||
return &searchTypes.Result{Items: []*searchTypes.ResultItem{}}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue