From 9bf455d91dee818869b634e8382417fc9b1fb643 Mon Sep 17 00:00:00 2001 From: Barak Amar Date: Sun, 16 Feb 2025 12:02:05 +0200 Subject: [PATCH 1/4] cosmosdb test client 5s timeout with 7 min retry connect to container --- pkg/kv/cosmosdb/main_test.go | 8 ++++---- pkg/testutil/cosmosdb.go | 12 ++++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pkg/kv/cosmosdb/main_test.go b/pkg/kv/cosmosdb/main_test.go index 00949657e79..15ba010ff94 100644 --- a/pkg/kv/cosmosdb/main_test.go +++ b/pkg/kv/cosmosdb/main_test.go @@ -26,11 +26,11 @@ var ( ) func TestCosmosDB(t *testing.T) { - kvtest.DriverTest(t, func(t testing.TB, ctx context.Context) kv.Store { - if runtime.GOOS == "darwin" { - t.Skipf("this test hangs for macOS users, and fails. skipping - see Issue#8476 for more details") - } + if runtime.GOOS == "darwin" { + t.Skipf("this test hangs for macOS users, and fails. skipping - see Issue#8476 for more details") + } + kvtest.DriverTest(t, func(t testing.TB, ctx context.Context) kv.Store { t.Helper() databaseClient, err := client.NewDatabase(testParams.Database) diff --git a/pkg/testutil/cosmosdb.go b/pkg/testutil/cosmosdb.go index e481932e50c..5e886f2d62d 100644 --- a/pkg/testutil/cosmosdb.go +++ b/pkg/testutil/cosmosdb.go @@ -13,7 +13,7 @@ import ( const ( CosmosDBLocalPort = "8081" - maxWait = 5 * time.Minute // Cosmosdb emulator takes time to start + maxWait = 7 * time.Minute // Cosmosdb emulator takes time to start ) var cosmosdbLocalURI string @@ -59,6 +59,13 @@ func GetCosmosDBInstance() (string, func(), error) { return "", nil, fmt.Errorf("joining urls: %w", err) } + client := http.Client{ + Transport: &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, //nolint:gosec // ignore self-signed cert for local testing using the emulator + }, + Timeout: 5 * time.Second, + } + dockerPool.MaxWait = maxWait log.Printf("Waiting up to %v for emulator to start", dockerPool.MaxWait) // Note: this hangs for macOS users, and fails. See https://github.com/treeverse/lakeFS/issues/8476 @@ -66,9 +73,6 @@ func GetCosmosDBInstance() (string, func(), error) { // waiting for cosmosdb container to be ready by issuing an HTTP get request with // exponential backoff retry. The response is not really meaningful for that case // and so is ignored - client := http.Client{Transport: &http.Transport{ - TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, //nolint:gosec // ignore self-signed cert for local testing using the emulator - }} resp, err := client.Get(p) if err != nil { return err From 674674bc2aac50e8fc8bc21b6f75e66fc37fa2cd Mon Sep 17 00:00:00 2001 From: Barak Amar Date: Sun, 16 Feb 2025 14:17:31 +0200 Subject: [PATCH 2/4] Update CosmosDB client configuration and timeout - No magic numbers - Adjusted the client timeout to 30 seconds for the CosmosDB client in the main_test.go file. - Updated the client configuration in the cosmosdb.go file to include a timeout of 5 seconds. --- pkg/kv/cosmosdb/main_test.go | 10 +++++++--- pkg/testutil/cosmosdb.go | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pkg/kv/cosmosdb/main_test.go b/pkg/kv/cosmosdb/main_test.go index 15ba010ff94..fada465c6a5 100644 --- a/pkg/kv/cosmosdb/main_test.go +++ b/pkg/kv/cosmosdb/main_test.go @@ -72,13 +72,17 @@ func TestMain(m *testing.M) { } defer cleanupFunc() + const clientTimeout = 30 * time.Second testParams = &kvparams.CosmosDB{ Endpoint: databaseURI, Key: "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==", Database: "test-db", - Client: &http.Client{Timeout: 30 * time.Second, Transport: &http.Transport{ - TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, //nolint:gosec // ignore self-signed cert for local testing using the emulator - }}, + Client: &http.Client{ + Timeout: clientTimeout, + Transport: &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, //nolint:gosec // ignore self-signed cert for local testing using the emulator + }, + }, StrongConsistency: false, } diff --git a/pkg/testutil/cosmosdb.go b/pkg/testutil/cosmosdb.go index 5e886f2d62d..02fed2cf946 100644 --- a/pkg/testutil/cosmosdb.go +++ b/pkg/testutil/cosmosdb.go @@ -59,11 +59,12 @@ func GetCosmosDBInstance() (string, func(), error) { return "", nil, fmt.Errorf("joining urls: %w", err) } + const clientTimeout = 5 * time.Second client := http.Client{ Transport: &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, //nolint:gosec // ignore self-signed cert for local testing using the emulator }, - Timeout: 5 * time.Second, + Timeout: clientTimeout, } dockerPool.MaxWait = maxWait From e002ac0b20ac5d599f78957b9298a833214403f4 Mon Sep 17 00:00:00 2001 From: Barak Amar Date: Sun, 16 Feb 2025 16:20:30 +0200 Subject: [PATCH 3/4] revert cosmosdb container time to spin back to 5 min --- pkg/testutil/cosmosdb.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/testutil/cosmosdb.go b/pkg/testutil/cosmosdb.go index 02fed2cf946..bb3946ff00a 100644 --- a/pkg/testutil/cosmosdb.go +++ b/pkg/testutil/cosmosdb.go @@ -13,7 +13,7 @@ import ( const ( CosmosDBLocalPort = "8081" - maxWait = 7 * time.Minute // Cosmosdb emulator takes time to start + maxWait = 5 * time.Minute // Cosmosdb emulator takes time to start ) var cosmosdbLocalURI string From 0ab2b9d515b5855f7393323d542c3ae0fad8e546 Mon Sep 17 00:00:00 2001 From: Barak Amar Date: Wed, 26 Feb 2025 22:17:11 +0200 Subject: [PATCH 4/4] change docker to linux based --- pkg/testutil/cosmosdb.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/testutil/cosmosdb.go b/pkg/testutil/cosmosdb.go index bb3946ff00a..68756c32269 100644 --- a/pkg/testutil/cosmosdb.go +++ b/pkg/testutil/cosmosdb.go @@ -26,7 +26,7 @@ func GetCosmosDBInstance() (string, func(), error) { cosmosdbDockerRunOptions := &dockertest.RunOptions{ Repository: "mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator", - Tag: "latest", + Tag: "vnext-preview", Env: []string{ "AZURE_COSMOS_EMULATOR_PARTITION_COUNT=100", },