Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes state cert tests #3596

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/infrastructure/docker-compose-sqlserver.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '2'
version: '3'
services:
sqlserver:
image: mcr.microsoft.com/mssql/server:2019-latest
Expand Down
12 changes: 4 additions & 8 deletions tests/certification/state/azure/cosmosdb/cosmosdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,13 @@ func TestAzureCosmosDBStorage(t *testing.T) {
"partitionKey": "mypartition",
}

test := func(setMeta, getMeta map[string]string, expectedValue string, expectedErr bool) {
test := func(setMeta, getMeta map[string]string, expectedValue string) {
// save state, default options: strong, last-write
err = client.SaveState(ctx, statestore, stateKey, []byte(stateValue), setMeta)
require.NoError(t, err)

// get state
item, err := client.GetState(ctx, statestore, stateKey, getMeta)
if expectedErr {
require.Error(t, err)
return
}
require.NoError(t, err)
assert.Equal(t, expectedValue, string(item.Value))

Expand All @@ -153,13 +149,13 @@ func TestAzureCosmosDBStorage(t *testing.T) {
}

// Test with no partition key
test(nil, meta1, stateValue, false)
test(nil, meta1, stateValue)

// Test with specific partition key
test(meta2, meta2, stateValue, false)
test(meta2, meta2, stateValue)

// Test with incorrect partition key
test(meta2, meta1, "", true)
test(meta2, meta1, "")

return nil
}
Expand Down
7 changes: 4 additions & 3 deletions tests/certification/state/memcached/memcached_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import (
"github.com/dapr/components-contrib/state"
"github.com/dapr/go-sdk/client"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

state_memcached "github.com/dapr/components-contrib/state/memcached"
"github.com/dapr/components-contrib/tests/certification/embedded"
"github.com/dapr/components-contrib/tests/certification/flow"
Expand All @@ -31,8 +34,6 @@ import (
state_loader "github.com/dapr/dapr/pkg/components/state"
dapr_testing "github.com/dapr/dapr/pkg/testing"
"github.com/dapr/kit/logger"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

const (
Expand Down Expand Up @@ -168,7 +169,7 @@ func TestMemcached(t *testing.T) {
key := certificationTestPrefix + "_expiresInOneSecondKey"
value := "This key will self-destroy in 1 second"

ttlExpirationTime := 1 * time.Second
ttlExpirationTime := 3 * time.Second
Copy link
Contributor Author

@elena-kolevska elena-kolevska Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test was failing sporadically because the key would expire before we could check for its presence.

ttlInSeconds := int(ttlExpirationTime.Seconds())
mapOptionsExpiringKey := map[string]string{
"ttlInSeconds": strconv.Itoa(ttlInSeconds),
Expand Down
14 changes: 14 additions & 0 deletions tests/certification/state/sqlserver/sqlserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ const (
)

func TestSqlServer(t *testing.T) {
// The default certificate created by the docker container sometimes contains a negative serial number.
// A TLS certificate with a negative serial number is invalid, although it was tolerated until 1.22
// Since Go 1.23 the default behavior has changed and the certificate is rejected.
// This environment variable is used to revert to the old behavior.
// Ref: https://github.com/microsoft/mssql-docker/issues/895
oldDebugValue := os.Getenv("GODEBUG")
err := os.Setenv("GODEBUG", "x509negativeserial=1")
if err != nil {
t.Fatalf("Failed to set GODEBUG environment variable: %v", err)
}
defer func() {
os.Setenv("GODEBUG", oldDebugValue)
}()

ports, err := dapr_testing.GetFreePorts(2)
require.NoError(t, err)

Expand Down
Loading