From 7dfadf4a1d7a2224d258f100250b574a8b9cde66 Mon Sep 17 00:00:00 2001 From: Liquan Pei Date: Thu, 21 Dec 2023 13:42:53 -0800 Subject: [PATCH] [BUG] Fix flaky test due to collection comparisons (#1563) ## Description of changes *Summarize the changes made by this PR.* - Improvements & Bug fixes - Fix flaky test due to collection comparisons - New functionality - ... ## Test plan *How are these changes tested?* - [ ] make test - [ ] CI pass ## Documentation Changes *Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the [docs repository](https://github.com/chroma-core/docs)?* --- go/coordinator/internal/coordinator/apis_test.go | 7 +++---- .../metastore/coordinator/model_db_convert_test.go | 4 ++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/go/coordinator/internal/coordinator/apis_test.go b/go/coordinator/internal/coordinator/apis_test.go index 1e9ffe0d375..62ff01ecec0 100644 --- a/go/coordinator/internal/coordinator/apis_test.go +++ b/go/coordinator/internal/coordinator/apis_test.go @@ -317,8 +317,7 @@ func TestCreateGetDeleteCollections(t *testing.T) { assert.NotContains(t, results, c1) assert.Len(t, results, len(sampleCollections)-1) - assert.Equal(t, sampleCollections[1:], results) - + assert.ElementsMatch(t, results, sampleCollections[1:]) byIDResult, err := c.GetCollections(ctx, c1.ID, nil, nil, common.DefaultTenant, common.DefaultDatabase) assert.NoError(t, err) assert.Empty(t, byIDResult) @@ -788,7 +787,7 @@ func TestCreateGetDeleteSegments(t *testing.T) { testTypeB := "test_type_b" result, err = c.GetSegments(ctx, types.NilUniqueID(), &testTypeB, nil, nil, types.NilUniqueID()) assert.NoError(t, err) - assert.Equal(t, sampleSegments[1:], result) + assert.ElementsMatch(t, result, sampleSegments[1:]) // Find by collection ID result, err = c.GetSegments(ctx, types.NilUniqueID(), nil, nil, nil, sampleCollections[0].ID) @@ -814,7 +813,7 @@ func TestCreateGetDeleteSegments(t *testing.T) { assert.NoError(t, err) assert.NotContains(t, results, s1) assert.Len(t, results, len(sampleSegments)-1) - assert.Equal(t, sampleSegments[1:], results) + assert.ElementsMatch(t, results, sampleSegments[1:]) // Duplicate delete throws an exception err = c.DeleteSegment(ctx, s1.ID) diff --git a/go/coordinator/internal/metastore/coordinator/model_db_convert_test.go b/go/coordinator/internal/metastore/coordinator/model_db_convert_test.go index d39c54d442e..67da68b1a76 100644 --- a/go/coordinator/internal/metastore/coordinator/model_db_convert_test.go +++ b/go/coordinator/internal/metastore/coordinator/model_db_convert_test.go @@ -1,6 +1,7 @@ package coordinator import ( + "sort" "testing" "github.com/chroma/chroma-coordinator/internal/metastore/db/dbmodel" @@ -42,6 +43,9 @@ func TestConvertCollectionMetadataToDB(t *testing.T) { }, } dbCollectionMetadataList = convertCollectionMetadataToDB("collectionID", metadata) + sort.Slice(dbCollectionMetadataList, func(i, j int) bool { + return *dbCollectionMetadataList[i].Key < *dbCollectionMetadataList[j].Key + }) assert.NotNil(t, dbCollectionMetadataList) assert.Len(t, dbCollectionMetadataList, 3) assert.Equal(t, "collectionID", dbCollectionMetadataList[0].CollectionID)