Skip to content

Commit

Permalink
fix(tests): Fixing acceptance tests and coveralls. (#352)
Browse files Browse the repository at this point in the history
* Fixing acceptance tests and coveralls.
  • Loading branch information
yasirfolio3 authored Dec 20, 2022
1 parent a4cbf60 commit 57e63d9
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 27 deletions.
22 changes: 11 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions plugins/userprofileservice/services/rest_ups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -39,6 +39,7 @@ type RestUPSTestSuite struct {
userProfile decision.UserProfile
MethodUsed string
savedUserProfile decision.UserProfile
wg *sync.WaitGroup
}

func (rups *RestUPSTestSuite) SetupTest() {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
14 changes: 7 additions & 7 deletions tests/acceptance/datafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}, {
Expand All @@ -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': [
Expand All @@ -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': [
Expand All @@ -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'},
Expand All @@ -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'},
Expand All @@ -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': [],
Expand Down
9 changes: 5 additions & 4 deletions tests/acceptance/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion tests/acceptance/test_acceptance/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def test_batch_valid_reponse(session_obj):
"variablesMap": {}
}
},
"revision": "20",
"revision": "21",
"sdkKey": "TkB2xhu8WEAHa4LphN3xZ2"
}"""

Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/test_acceptance/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
expected_config = """{
"environmentKey": "production",
"sdkKey": "KZbunNn9bVfBWLpZPq2XC4",
"revision": "130",
"revision": "131",
"experimentsMap": {
"ab_test1": {
"id": "16911963060",
Expand Down

0 comments on commit 57e63d9

Please sign in to comment.