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

[TT-13695] Testing fixes, skip dangerous tests #6736

Merged
merged 3 commits into from
Dec 5, 2024
Merged
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ petstore.json
coprocess_gen_test.go
session_state_gen_test.go
__pycache__/
tyk.test
*.test
*.test.log
tyk-gateway.pid
tests/pkgs.*

tyk_linux_*
.aider*
Expand Down
5 changes: 3 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ tasks:
- go mod tidy

lint:all:
desc: "Run more specific linters"
deps:
- lint:config
- lint:imports
Expand All @@ -89,12 +90,12 @@ tasks:
lint:config:
internal: true
cmds:
- go test -count 1 -v ./cli/linter/...
- go test -count 1 ./cli/linter/...

lint:x-tyk-gateway:
internal: true
cmds:
- go test -count 1 -v -run=TestXTykGateway_Lint ./apidef/oas/
- go test -count 1 -run=TestXTykGateway_Lint ./apidef/oas/

setup:
desc: "Setup the project including dependencies and git hooks using lefthooks"
Expand Down
32 changes: 17 additions & 15 deletions gateway/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func TestApiHandlerPostDupPath(t *testing.T) {
}

func TestKeyHandler(t *testing.T) {
test.Exclusive(t) // Uses DeleteAllKeys, need to limit parallelism.
t.Skip() // DeleteAllKeys interferes with other tests.

ts := StartTest(nil)
defer ts.Close()
Expand Down Expand Up @@ -285,6 +285,8 @@ func TestKeyHandler(t *testing.T) {
})

t.Run("Create key with policy", func(t *testing.T) {
keyID := uuid.New()

_, _ = ts.Run(t, []test.TestCase{
{
Method: "POST",
Expand All @@ -309,7 +311,7 @@ func TestKeyHandler(t *testing.T) {
},
{
Method: "POST",
Path: "/tyk/keys/my_key_id",
Path: "/tyk/keys/" + keyID,
Data: string(withPolicyJSON),
AdminAuth: true,
Code: 200,
Expand All @@ -321,26 +323,26 @@ func TestKeyHandler(t *testing.T) {
},
{
Method: "GET",
Path: "/sample/?authorization=my_key_id",
Path: "/sample/?authorization=" + keyID,
Code: 200,
},
{
Method: "GET",
Path: "/tyk/keys/my_key_id" + "?api_id=test",
Path: "/tyk/keys/" + keyID + "?api_id=test",
AdminAuth: true,
Code: 200,
BodyMatch: `"quota_max":5`,
},
{
Method: "GET",
Path: "/tyk/keys/my_key_id" + "?api_id=test",
Path: "/tyk/keys/" + keyID + "?api_id=test",
AdminAuth: true,
Code: 200,
BodyMatch: `"quota_remaining":4`,
},
}...)

ts.Gw.GlobalSessionManager.Store().DeleteAllKeys() // exclusive
ts.Gw.GlobalSessionManager.Store().DeleteAllKeys()
})

_, knownKey := ts.CreateSession(func(s *user.SessionState) {
Expand Down Expand Up @@ -646,8 +648,6 @@ func BenchmarkKeyHandler_CreateKeyHandler(b *testing.B) {
}

func TestKeyHandler_DeleteKeyWithQuota(t *testing.T) {
test.Exclusive(t) // Uses quota, need to limit parallelism due to DeleteAllKeys.

const testAPIID = "testAPIID"
const orgId = "default"

Expand Down Expand Up @@ -830,7 +830,7 @@ func TestUpdateKeyWithCert(t *testing.T) {
}

func TestKeyHandler_CheckKeysNotDuplicateOnUpdate(t *testing.T) {
test.Exclusive(t) // Uses DeleteAllKeys, need to limit parallelism.
t.Skip() // DeleteAllKeys interferes with other tests.

ts := StartTest(nil)
defer ts.Close()
Expand Down Expand Up @@ -884,7 +884,9 @@ func TestKeyHandler_CheckKeysNotDuplicateOnUpdate(t *testing.T) {

for _, tc := range cases {
t.Run(tc.Name, func(t *testing.T) {
ts.Gw.GlobalSessionManager.Store().DeleteAllKeys() // exclusive
// Deletes keyspace
ts.Gw.GlobalSessionManager.Store().DeleteAllKeys()

session := CreateStandardSession()
session.AccessRights = map[string]user.AccessDefinition{"test": {
APIID: "test", Versions: []string{"v1"},
Expand Down Expand Up @@ -912,7 +914,7 @@ func TestKeyHandler_CheckKeysNotDuplicateOnUpdate(t *testing.T) {
}

func TestHashKeyHandler(t *testing.T) {
test.Exclusive(t) // Uses DeleteAllKeys, need to limit parallelism.
t.Skip() // DeleteAllKeys interferes with other tests.

conf := func(globalConf *config.Config) {
// make it to use hashes for Redis keys
Expand Down Expand Up @@ -940,7 +942,7 @@ func TestHashKeyHandler(t *testing.T) {
gwConf := ts.Gw.GetConfig()
gwConf.HashKeyFunction = tc.hashFunction
ts.Gw.SetConfig(gwConf)
ok := ts.Gw.GlobalSessionManager.Store().DeleteAllKeys() // exclusive
ok := ts.Gw.GlobalSessionManager.Store().DeleteAllKeys()
assert.True(t, ok)

t.Run(fmt.Sprintf("%sHash fn: %s", tc.desc, tc.hashFunction), func(t *testing.T) {
Expand Down Expand Up @@ -1091,7 +1093,7 @@ func (ts *Test) testHashKeyHandlerHelper(t *testing.T, expectedHashSize int) {
}}
withAccessJSON := test.MarshalJSON(t)(withAccess)

myKey := "my_key_id"
myKey := uuid.New()
myKeyHash := storage.HashKey(ts.Gw.generateToken("default", myKey), ts.Gw.GetConfig().HashKeys)

if len(myKeyHash) != expectedHashSize {
Expand Down Expand Up @@ -1265,7 +1267,7 @@ func TestHashKeyListingDisabled(t *testing.T) {
}}
withAccessJSON := test.MarshalJSON(t)(withAccess)

myKey := "my_key_id"
myKey := uuid.New()
myKeyHash := storage.HashKey(ts.Gw.generateToken("default", myKey), ts.Gw.GetConfig().HashKeys)

t.Run("Create, get and delete key with key hashing", func(t *testing.T) {
Expand Down Expand Up @@ -1383,7 +1385,7 @@ func TestKeyHandler_HashingDisabled(t *testing.T) {
}}
withAccessJSON := test.MarshalJSON(t)(withAccess)

myKeyID := "my_key_id"
myKeyID := uuid.New()
token := ts.Gw.generateToken("default", myKeyID)
myKeyHash := storage.HashKey(token, ts.Gw.GetConfig().HashKeys)

Expand Down
20 changes: 9 additions & 11 deletions gateway/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func TestSkipTargetPassEscapingOffWithSkipURLCleaningTrue(t *testing.T) {
}

func TestQuota(t *testing.T) {
test.Exclusive(t) // Uses quota, need to limit parallelism due to DeleteAllKeys.
t.Skip() // DeleteScanMatch interferes with other tests.

ts := StartTest(nil)
t.Cleanup(ts.Close)
Expand Down Expand Up @@ -942,7 +942,7 @@ func TestGatewayHealthCheck(t *testing.T) {
}

func TestCacheAllSafeRequests(t *testing.T) {
test.Exclusive(t) // Need to limit parallelism due to DeleteScanMatch.
t.Skip() // DeleteScanMatch interferes with other tests.

ts := StartTest(nil)
cache := storage.RedisCluster{KeyPrefix: "cache-", ConnectionHandler: ts.Gw.StorageConnectionHandler}
Expand Down Expand Up @@ -972,7 +972,7 @@ func TestCacheAllSafeRequests(t *testing.T) {
}

func TestCacheAllSafeRequestsWithCachedHeaders(t *testing.T) {
test.Exclusive(t) // Need to limit parallelism due to DeleteScanMatch.
t.Skip() // DeleteScanMatch interferes with other tests.

ts := StartTest(nil)
cache := storage.RedisCluster{KeyPrefix: "cache-", ConnectionHandler: ts.Gw.StorageConnectionHandler}
Expand Down Expand Up @@ -1018,7 +1018,7 @@ func TestCacheAllSafeRequestsWithCachedHeaders(t *testing.T) {
}

func TestCacheWithAdvanceUrlRewrite(t *testing.T) {
test.Exclusive(t) // Need to limit parallelism due to DeleteScanMatch.
t.Skip() // DeleteScanMatch interferes with other tests.

ts := StartTest(nil)
cache := storage.RedisCluster{KeyPrefix: "cache-", ConnectionHandler: ts.Gw.StorageConnectionHandler}
Expand Down Expand Up @@ -1077,7 +1077,7 @@ func TestCacheWithAdvanceUrlRewrite(t *testing.T) {
}

func TestCachePostRequest(t *testing.T) {
test.Exclusive(t) // Need to limit parallelism due to DeleteScanMatch.
t.Skip() // DeleteScanMatch interferes with other tests.

ts := StartTest(nil)
cache := storage.RedisCluster{KeyPrefix: "cache-", ConnectionHandler: ts.Gw.StorageConnectionHandler}
Expand Down Expand Up @@ -1124,7 +1124,7 @@ func TestCachePostRequest(t *testing.T) {
}

func TestAdvanceCachePutRequest(t *testing.T) {
test.Exclusive(t) // Need to limit parallelism due to DeleteScanMatch.
t.Skip() // DeleteScanMatch interferes with other tests.

ts := StartTest(nil)
cache := storage.RedisCluster{KeyPrefix: "cache-", ConnectionHandler: ts.Gw.StorageConnectionHandler}
Expand Down Expand Up @@ -1217,7 +1217,7 @@ func TestAdvanceCachePutRequest(t *testing.T) {
}

func TestCacheAllSafeRequestsWithAdvancedCacheEndpoint(t *testing.T) {
test.Exclusive(t) // Need to limit parallelism due to DeleteScanMatch.
t.Skip() // DeleteScanMatch interferes with other tests.

ts := StartTest(nil)
cache := storage.RedisCluster{KeyPrefix: "cache-", ConnectionHandler: ts.Gw.StorageConnectionHandler}
Expand Down Expand Up @@ -1256,7 +1256,7 @@ func TestCacheAllSafeRequestsWithAdvancedCacheEndpoint(t *testing.T) {
}

func TestCacheEtag(t *testing.T) {
test.Exclusive(t) // Test is exclusive due to deleting all the cache from redis (interference).
t.Skip() // DeleteScanMatch interferes with other tests.

ts := StartTest(nil)
cache := storage.RedisCluster{KeyPrefix: "cache-", ConnectionHandler: ts.Gw.StorageConnectionHandler}
Expand Down Expand Up @@ -1294,8 +1294,6 @@ func TestCacheEtag(t *testing.T) {
}

func TestOldCachePlugin(t *testing.T) {
test.Exclusive(t) // Test uses cache-* while other tests delete it.

api := BuildAPI(func(spec *APISpec) {
spec.Proxy.ListenPath = "/"
UpdateAPIVersion(spec, "v1", func(version *apidef.VersionInfo) {
Expand Down Expand Up @@ -1340,7 +1338,7 @@ func TestOldCachePlugin(t *testing.T) {
}

func TestAdvanceCacheTimeoutPerEndpoint(t *testing.T) {
test.Exclusive(t) // Need to limit parallelism due to DeleteScanMatch.
t.Skip() // DeleteScanMatch interferes with other tests.

ts := StartTest(nil)
cache := storage.RedisCluster{KeyPrefix: "cache-", ConnectionHandler: ts.Gw.StorageConnectionHandler}
Expand Down
1 change: 0 additions & 1 deletion gateway/host_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ func (w *testEventHandler) HandleEvent(em config.EventMessage) {
w.cb(em)
}

// // ToDo check why it blocks
func TestHostChecker(t *testing.T) {
ts := StartTest(func(globalConf *config.Config) {
globalConf.UptimeTests.PollerGroup = uuid.New()
Expand Down
2 changes: 1 addition & 1 deletion gateway/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func TestBaseMiddleware_getAuthToken(t *testing.T) {
}

func TestSessionLimiter_RedisQuotaExceeded_PerAPI(t *testing.T) {
test.Exclusive(t) // Uses DeleteAllKeys, need to limit parallelism.
t.Skip() // DeleteAllKeys interferes with other tests.

g := StartTest(nil)
defer g.Close()
Expand Down
5 changes: 4 additions & 1 deletion gateway/mw_auth_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,11 @@ func TestMurmur3CharBug(t *testing.T) {
}

func TestSignatureValidation(t *testing.T) {
test.Flaky(t) // Test uses StorageConnectionHandler (singleton).

ts := StartTest(nil)
defer ts.Close()
t.Cleanup(ts.Close)

api := BuildAPI(func(spec *APISpec) {
spec.UseKeylessAccess = false
spec.Proxy.ListenPath = "/"
Expand Down
2 changes: 1 addition & 1 deletion gateway/mw_external_oauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ func TestExternalOAuthMiddleware_introspection(t *testing.T) {
}...)

t.Run("cache", func(t *testing.T) {
test.Exclusive(t) // Uses DeleteAllKeys, need to limit parallelism.
t.Skip() // DeleteAllKeys interferes with other tests.

api.ExternalOAuth.Providers[0].Introspection.Cache.Enabled = true
api.ExternalOAuth.Providers[0].Introspection.Cache.Timeout = 0
Expand Down
10 changes: 6 additions & 4 deletions gateway/mw_organisation_activity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func (ts *Test) testPrepareProcessRequestQuotaLimit(tb testing.TB, data map[stri
}

func TestOrganizationMonitorEnabled(t *testing.T) {
test.Flaky(t) // Test uses StorageConnectionHandler (singleton).

conf := func(globalConf *config.Config) {
globalConf.EnforceOrgQuotas = true
globalConf.ExperimentalProcessOrgOffThread = false
Expand Down Expand Up @@ -79,7 +81,7 @@ func TestOrganizationMonitorEnabled(t *testing.T) {
}

func TestProcessRequestLiveQuotaLimit(t *testing.T) {
test.Flaky(t) // TODO: TT-5254
test.Flaky(t) // Test uses StorageConnectionHandler (singleton).

conf := func(globalConf *config.Config) {
globalConf.EnforceOrgQuotas = true
Expand Down Expand Up @@ -154,7 +156,7 @@ func BenchmarkProcessRequestLiveQuotaLimit(b *testing.B) {
}

func TestProcessRequestOffThreadQuotaLimit(t *testing.T) {
test.Flaky(t) // TODO: TT-5254
test.Flaky(t) // Test uses StorageConnectionHandler (singleton).

conf := func(globalConf *config.Config) {
globalConf.EnforceOrgQuotas = true
Expand Down Expand Up @@ -251,7 +253,7 @@ func BenchmarkProcessRequestOffThreadQuotaLimit(b *testing.B) {
}

func TestProcessRequestLiveRedisRollingLimiter(t *testing.T) {
test.Flaky(t) // TODO: TT-5254
test.Flaky(t) // Test uses StorageConnectionHandler (singleton).

ts := StartTest(nil)
defer ts.Close()
Expand Down Expand Up @@ -340,7 +342,7 @@ func BenchmarkProcessRequestLiveRedisRollingLimiter(b *testing.B) {
}

func TestProcessRequestOffThreadRedisRollingLimiter(t *testing.T) {
test.Flaky(t) // TODO: TT-5254
test.Flaky(t) // Test uses StorageConnectionHandler (singleton).

// setup global config
conf := func(globalConf *config.Config) {
Expand Down
4 changes: 1 addition & 3 deletions gateway/mw_rate_limiting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ func TestRateLimit_Unlimited(t *testing.T) {
}

func TestNeverRenewQuota(t *testing.T) {
test.Exclusive(t) // Uses quota, need to limit parallelism due to DeleteAllKeys.

g := StartTest(nil)
defer g.Close()

Expand Down Expand Up @@ -193,7 +191,7 @@ func TestMwRateLimiting_DepthLimit(t *testing.T) {
}

func providerCustomRatelimitKey(t *testing.T, limiter string) {
test.Exclusive(t) // Uses DeleteAllKeys, need to limit parallelism.
t.Skip() // DeleteAllKeys interferes with other tests.

t.Helper()

Expand Down
4 changes: 3 additions & 1 deletion gateway/mw_streaming_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@ streams:
}

func TestAsyncAPIHttp(t *testing.T) {
t.Skip() // Expensive. Runs containerized tests. 15s.

var tests = []struct {
name string
consumerGroup string
Expand Down Expand Up @@ -739,7 +741,7 @@ func waitForAPIToBeLoaded(ts *Test) error {
}

func TestWebSocketConnectionClosedOnAPIReload(t *testing.T) {
t.Skip()
t.Skip() // Is this also skipped because running containers is slow?
ctx := context.Background()
kafkaContainer, err := kafka.Run(ctx, "confluentinc/confluent-local:7.5.0")
if err != nil {
Expand Down
Loading
Loading