From 57e63d9e9147387774d78e2c00335e020d637df2 Mon Sep 17 00:00:00 2001 From: Yasir Folio3 <39988750+yasirfolio3@users.noreply.github.com> Date: Wed, 21 Dec 2022 00:15:15 +0500 Subject: [PATCH] fix(tests): Fixing acceptance tests and coveralls. (#352) * Fixing acceptance tests and coveralls. --- .travis.yml | 22 +++++++++---------- .../services/rest_ups_test.go | 16 +++++++++++--- tests/acceptance/datafile.py | 14 ++++++------ tests/acceptance/requirements.txt | 9 ++++---- .../acceptance/test_acceptance/test_batch.py | 2 +- .../acceptance/test_acceptance/test_config.py | 2 +- 6 files changed, 38 insertions(+), 27 deletions(-) diff --git a/.travis.yml b/.travis.yml index 39aeb1f4..34606294 100644 --- a/.travis.yml +++ b/.travis.yml @@ -82,17 +82,17 @@ jobs: script: - MYHOST="http://localhost:8080" make test-acceptance - - stage: 'Trigger FSC Tests' - if: (branch = master AND type = push) OR type = pull_request OR tag IS present - env: - SDK=agent - SDK_BRANCH=$(if [ -z "$TRAVIS_PULL_REQUEST_BRANCH" ]; then echo ${TRAVIS_BRANCH}; else echo "$TRAVIS_PULL_REQUEST_BRANCH"; fi) - cache: false - before_install: - ./scripts/pull_travis_ci_tools.sh - install: skip - script: - - "$HOME/travisci-tools/trigger-script-with-status-update.sh" + # - stage: 'Trigger FSC Tests' + # if: (branch = master AND type = push) OR type = pull_request OR tag IS present + # env: + # SDK=agent + # SDK_BRANCH=$(if [ -z "$TRAVIS_PULL_REQUEST_BRANCH" ]; then echo ${TRAVIS_BRANCH}; else echo "$TRAVIS_PULL_REQUEST_BRANCH"; fi) + # cache: false + # before_install: + # ./scripts/pull_travis_ci_tools.sh + # install: skip + # script: + # - "$HOME/travisci-tools/trigger-script-with-status-update.sh" - stage: 'Test Build using latest tag (no upload)' name: linux diff --git a/plugins/userprofileservice/services/rest_ups_test.go b/plugins/userprofileservice/services/rest_ups_test.go index 22d9538b..4223b6c7 100644 --- a/plugins/userprofileservice/services/rest_ups_test.go +++ b/plugins/userprofileservice/services/rest_ups_test.go @@ -21,8 +21,8 @@ import ( "encoding/json" "net/http" "net/http/httptest" + "sync" "testing" - "time" "github.com/go-chi/render" "github.com/optimizely/agent/pkg/handlers" @@ -39,6 +39,7 @@ type RestUPSTestSuite struct { userProfile decision.UserProfile MethodUsed string savedUserProfile decision.UserProfile + wg *sync.WaitGroup } func (rups *RestUPSTestSuite) SetupTest() { @@ -70,6 +71,9 @@ func (rups *RestUPSTestSuite) SetupTest() { } rups.savedUserProfile = convertToUserProfile(userProfile, rups.ups.getUserIDKey()) w.WriteHeader(http.StatusOK) + if rups.wg != nil { + rups.wg.Done() + } case "/ups/lookup": userProfileMap := convertUserProfileToMap(rups.userProfile, rups.ups.getUserIDKey()) w.Header().Set("Content-Type", "application/json") @@ -178,8 +182,11 @@ func (rups *RestUPSTestSuite) TestSaveDefaultPOST() { func (rups *RestUPSTestSuite) TestSaveDefaultPOSTAsync() { rups.ups.Async = true + rups.wg = &sync.WaitGroup{} + rups.wg.Add(1) rups.ups.Save(rups.userProfile) - time.Sleep(100 * time.Millisecond) + rups.wg.Wait() + rups.wg = nil rups.Equal(rups.userProfile, rups.savedUserProfile) rups.Equal("POST", rups.MethodUsed) } @@ -193,9 +200,12 @@ func (rups *RestUPSTestSuite) TestSaveWithGetMethod() { func (rups *RestUPSTestSuite) TestSaveWithGetMethodAsync() { rups.ups.Async = true + rups.wg = &sync.WaitGroup{} rups.ups.SaveMethod = "GET" + rups.wg.Add(1) rups.ups.Save(rups.userProfile) - time.Sleep(100 * time.Millisecond) + rups.wg.Wait() + rups.wg = nil rups.Equal(rups.userProfile, rups.savedUserProfile) rups.Equal("GET", rups.MethodUsed) } diff --git a/tests/acceptance/datafile.py b/tests/acceptance/datafile.py index 010655c4..3b8d40d9 100644 --- a/tests/acceptance/datafile.py +++ b/tests/acceptance/datafile.py @@ -38,11 +38,11 @@ {'experimentIds': [], 'id': '16907463855', 'key': 'feature_3', 'rolloutId': '16909553406', 'variables': []}, {'experimentIds': [], 'id': '16912161768', 'key': 'feature_4', 'rolloutId': '16943340293', - 'variables': []}], 'groups': [], 'projectId': '16931203314', 'revision': '130', + 'variables': []}], 'groups': [], 'projectId': '16931203314', 'revision': '131', 'rollouts': [{'experiments': [{'audienceConditions': [], 'audienceIds': [], 'forcedVariations': {}, 'id': 'default-rollout-12672-16935023792', 'key': 'default-rollout-12672-16935023792', - 'layerId': 'default-layer-rollout-12672-16935023792', 'status': 'Running', + 'layerId': 'rollout-12672-16935023792', 'status': 'Running', 'trafficAllocation': [{'endOfRange': 10000, 'entityId': '35771'}], 'variations': [{'featureEnabled': False, 'id': '35771', 'key': 'off', 'variables': []}]}], 'id': 'rollout-12672-16935023792'}, { @@ -60,7 +60,7 @@ 'variables': []}]}, {'audienceConditions': [], 'audienceIds': [], 'forcedVariations': {}, 'id': 'default-16917900798', 'key': 'default-16917900798', - 'layerId': 'default-layer-16917900798', 'status': 'Running', + 'layerId': '16917900798', 'status': 'Running', 'trafficAllocation': [{'endOfRange': 10000, 'entityId': '35770'}], 'variations': [ {'featureEnabled': False, 'id': '35770', 'key': 'off', 'variables': []}]}], 'id': '16917900798'}, {'experiments': [ @@ -69,7 +69,7 @@ 'trafficAllocation': [{'endOfRange': 10000, 'entityId': '16927890136'}], 'variations': [{'featureEnabled': True, 'id': '16927890136', 'key': '16927890136', 'variables': []}]}, {'audienceConditions': [], 'audienceIds': [], 'forcedVariations': {}, 'id': 'default-16917103311', - 'key': 'default-16917103311', 'layerId': 'default-layer-16917103311', 'status': 'Running', + 'key': 'default-16917103311', 'layerId': '16917103311', 'status': 'Running', 'trafficAllocation': [{'endOfRange': 10000, 'entityId': '35769'}], 'variations': [{'featureEnabled': False, 'id': '35769', 'key': 'off', 'variables': []}]}], 'id': '16917103311'}, {'experiments': [ @@ -87,7 +87,7 @@ {'id': '16937161477', 'value': '1'}, {'id': '16916052157', 'value': 'hello'}]}]}, {'audienceConditions': [], 'audienceIds': [], 'forcedVariations': {}, 'id': 'default-16928980969', - 'key': 'default-16928980969', 'layerId': 'default-layer-16928980969', 'status': 'Running', + 'key': 'default-16928980969', 'layerId': '16928980969', 'status': 'Running', 'trafficAllocation': [{'endOfRange': 10000, 'entityId': '35768'}], 'variations': [ {'featureEnabled': False, 'id': '35768', 'key': 'off', 'variables': [{'id': '16932993089', 'value': 'true'}, {'id': '16923002469', 'value': '5.6'}, @@ -97,7 +97,7 @@ 'key': '16907440927', 'layerId': '16909553406', 'status': 'Running', 'trafficAllocation': [], 'variations': [{'featureEnabled': True, 'id': '16908510336', 'key': '16908510336', 'variables': []}]}, {'audienceConditions': [], 'audienceIds': [], 'forcedVariations': {}, 'id': 'default-16909553406', - 'key': 'default-16909553406', 'layerId': 'default-layer-16909553406', 'status': 'Running', + 'key': 'default-16909553406', 'layerId': '16909553406', 'status': 'Running', 'trafficAllocation': [{'endOfRange': 10000, 'entityId': '35767'}], 'variations': [{'featureEnabled': False, 'id': '35767', 'key': 'off', 'variables': []}]}], 'id': '16909553406'}, @@ -108,7 +108,7 @@ {'featureEnabled': True, 'id': '16925940659', 'key': '16925940659', 'variables': []}]}, {'audienceConditions': [], 'audienceIds': [], 'forcedVariations': {}, 'id': 'default-16943340293', 'key': 'default-16943340293', - 'layerId': 'default-layer-16943340293', 'status': 'Running', + 'layerId': '16943340293', 'status': 'Running', 'trafficAllocation': [{'endOfRange': 10000, 'entityId': '35766'}], 'variations': [{'featureEnabled': False, 'id': '35766', 'key': 'off', 'variables': []}]}], 'id': '16943340293'}], 'sdkKey': 'KZbunNn9bVfBWLpZPq2XC4', 'typedAudiences': [], diff --git a/tests/acceptance/requirements.txt b/tests/acceptance/requirements.txt index b76ed147..ce7459f0 100644 --- a/tests/acceptance/requirements.txt +++ b/tests/acceptance/requirements.txt @@ -1,4 +1,5 @@ -pytest>=5.3.2 -pytest-clarity>=0.2.0a1 -requests>=2.22.0 -openapi_core>=0.13.4 +pytest==7.0.0 +pytest-clarity==1.0.1 +requests==2.27.1 +openapi_core==0.14.2 +openapi_spec_validator==0.4.0 \ No newline at end of file diff --git a/tests/acceptance/test_acceptance/test_batch.py b/tests/acceptance/test_acceptance/test_batch.py index 8a651b8b..5e92dc93 100644 --- a/tests/acceptance/test_acceptance/test_batch.py +++ b/tests/acceptance/test_acceptance/test_batch.py @@ -186,7 +186,7 @@ def test_batch_valid_reponse(session_obj): "variablesMap": {} } }, - "revision": "20", + "revision": "21", "sdkKey": "TkB2xhu8WEAHa4LphN3xZ2" }""" diff --git a/tests/acceptance/test_acceptance/test_config.py b/tests/acceptance/test_acceptance/test_config.py index 1f46703a..be4b01cc 100644 --- a/tests/acceptance/test_acceptance/test_config.py +++ b/tests/acceptance/test_acceptance/test_config.py @@ -9,7 +9,7 @@ expected_config = """{ "environmentKey": "production", "sdkKey": "KZbunNn9bVfBWLpZPq2XC4", - "revision": "130", + "revision": "131", "experimentsMap": { "ab_test1": { "id": "16911963060",