Skip to content

Commit 523edce

Browse files
authored
fix: parallel test (#978)
1 parent 18944c0 commit 523edce

File tree

5 files changed

+229
-103
lines changed

5 files changed

+229
-103
lines changed

.circleci/config.yml

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,80 @@ jobs:
1010
MONGO_INITDB_ROOT_USERNAME: root
1111
MONGO_INITDB_ROOT_PASSWORD: root
1212
resource_class: large
13+
parameters:
14+
plugin:
15+
type: string
1316
steps:
1417
- checkout
15-
- run: echo $'\n[mysqld]\ncharacter_set_server=utf8mb4' >> /etc/mysql/mysql.cnf
16-
- run: (cd .circleci/ && ./doTests.sh)
18+
- run: echo $'\n[mysqld]\ncharacter_set_server=utf8mb4\nmax_connections=10000' >> /etc/mysql/mysql.cnf
19+
- run: apt-get -y -q install postgresql-9.5 postgresql-client-9.5 postgresql-contrib-9.5 sudo
20+
- run: echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.5/main/pg_hba.conf
21+
- run: echo "listen_addresses='*'" >> /etc/postgresql/9.5/main/postgresql.conf
22+
- run: (cd .circleci/ && ./doTests.sh << parameters.plugin >>)
23+
- slack/status
24+
25+
mark-passed:
26+
docker:
27+
- image: rishabhpoddar/supertokens_core_testing
28+
steps:
29+
- checkout
30+
- run: (cd .circleci && ./markPassed.sh)
1731
- slack/status
1832

1933
workflows:
2034
version: 2
2135
tagged-build:
2236
jobs:
2337
- test:
38+
plugin: sqlite
39+
name: test-sqlite
40+
context:
41+
- slack-notification
42+
filters:
43+
tags:
44+
only: /dev-v[0-9]+(\.[0-9]+)*/
45+
branches:
46+
ignore: /.*/
47+
- test:
48+
plugin: mongodb
49+
name: test-mongodb
50+
context:
51+
- slack-notification
52+
filters:
53+
tags:
54+
only: /dev-v[0-9]+(\.[0-9]+)*/
55+
branches:
56+
ignore: /.*/
57+
- test:
58+
plugin: postgresql
59+
name: test-postgresql
60+
context:
61+
- slack-notification
62+
filters:
63+
tags:
64+
only: /dev-v[0-9]+(\.[0-9]+)*/
65+
branches:
66+
ignore: /.*/
67+
- test:
68+
plugin: mysql
69+
name: test-mysql
70+
context:
71+
- slack-notification
72+
filters:
73+
tags:
74+
only: /dev-v[0-9]+(\.[0-9]+)*/
75+
branches:
76+
ignore: /.*/
77+
- mark-passed:
2478
context:
2579
- slack-notification
2680
filters:
2781
tags:
2882
only: /dev-v[0-9]+(\.[0-9]+)*/
2983
branches:
30-
ignore: /.*/
84+
ignore: /.*/
85+
requires:
86+
- test-sqlite
87+
- test-mongodb
88+
- test-postgresql
89+
- test-mysql

.circleci/doTests.sh

Lines changed: 130 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ function cleanup {
77
trap cleanup EXIT
88
cleanup
99

10+
pluginToTest=$1
11+
1012
pinnedDBJson=$(curl -s -X GET \
1113
'https://api.supertokens.io/0/plugin/pinned?planType=FREE' \
1214
-H 'api-version: 0')
@@ -86,126 +88,154 @@ do
8688

8789
i=$((i+1))
8890

89-
if [[ $currPinnedDb == "sqlite" ]]
91+
if [[ $currPinnedDb == $pluginToTest ]]
9092
then
91-
# shellcheck disable=SC2034
92-
continue=1
93-
else
94-
response=$(curl -s -X GET \
95-
"https://api.supertokens.io/0/plugin-interface/dependency/plugin/latest?password=$SUPERTOKENS_API_KEY&planType=FREE&mode=DEV&version=$piVersion&pluginName=$currPinnedDb" \
96-
-H 'api-version: 0')
97-
if [[ $(echo "$response" | jq .plugin) == "null" ]]
98-
then
99-
echo "fetching latest X.Y version for $currPinnedDb given plugin-interface X.Y version: $piVersion gave response: $response"
100-
exit 1
101-
fi
102-
pinnedDbVersionX2=$(echo $response | jq .plugin | tr -d '"')
10393

104-
response=$(curl -s -X GET \
105-
"https://api.supertokens.io/0/plugin/latest?password=$SUPERTOKENS_API_KEY&planType=FREE&mode=DEV&version=$pinnedDbVersionX2&name=$currPinnedDb" \
106-
-H 'api-version: 0')
107-
if [[ $(echo "$response" | jq .tag) == "null" ]]
94+
echo ""
95+
echo ""
96+
echo ""
97+
echo ""
98+
echo ""
99+
echo "===== testing $currPinnedDb with plugin-interface $currVersion ====="
100+
echo ""
101+
echo ""
102+
echo ""
103+
echo ""
104+
echo ""
105+
106+
if [[ $currPinnedDb == "sqlite" ]]
108107
then
109-
echo "fetching latest X.Y.Z version for $currPinnedDb, X.Y version: $pinnedDbVersionX2 gave response: $response"
110-
exit 1
108+
# shellcheck disable=SC2034
109+
continue=1
110+
else
111+
response=$(curl -s -X GET \
112+
"https://api.supertokens.io/0/plugin-interface/dependency/plugin/latest?password=$SUPERTOKENS_API_KEY&planType=FREE&mode=DEV&version=$piVersion&pluginName=$currPinnedDb" \
113+
-H 'api-version: 0')
114+
if [[ $(echo "$response" | jq .plugin) == "null" ]]
115+
then
116+
echo "fetching latest X.Y version for $currPinnedDb given plugin-interface X.Y version: $piVersion gave response: $response"
117+
exit 1
118+
fi
119+
pinnedDbVersionX2=$(echo $response | jq .plugin | tr -d '"')
120+
121+
response=$(curl -s -X GET \
122+
"https://api.supertokens.io/0/plugin/latest?password=$SUPERTOKENS_API_KEY&planType=FREE&mode=DEV&version=$pinnedDbVersionX2&name=$currPinnedDb" \
123+
-H 'api-version: 0')
124+
if [[ $(echo "$response" | jq .tag) == "null" ]]
125+
then
126+
echo "fetching latest X.Y.Z version for $currPinnedDb, X.Y version: $pinnedDbVersionX2 gave response: $response"
127+
exit 1
128+
fi
129+
pinnedDbVersionTag=$(echo "$response" | jq .tag | tr -d '"')
130+
pinnedDbVersion=$(echo "$response" | jq .version | tr -d '"')
131+
./startDb.sh "$currPinnedDb"
111132
fi
112-
pinnedDbVersionTag=$(echo "$response" | jq .tag | tr -d '"')
113-
pinnedDbVersion=$(echo "$response" | jq .version | tr -d '"')
114-
./startDb.sh "$currPinnedDb"
115-
fi
116133

117-
cd ../../
118-
git clone [email protected]:supertokens/supertokens-root.git
119-
cd supertokens-root
134+
cd ../../
135+
git clone [email protected]:supertokens/supertokens-root.git
136+
cd supertokens-root
120137

121-
update-alternatives --install "/usr/bin/java" "java" "/usr/java/jdk-15.0.1/bin/java" 2
122-
update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/jdk-15.0.1/bin/javac" 2
123-
124-
coreX=$(cut -d'.' -f1 <<<"$coreVersion")
125-
coreY=$(cut -d'.' -f2 <<<"$coreVersion")
126-
if [[ $currPinnedDb == "sqlite" ]]
127-
then
128-
echo -e "core,$coreX.$coreY\nplugin-interface,$piVersion" > modules.txt
129-
else
130-
echo -e "core,$coreX.$coreY\nplugin-interface,$piVersion\n$currPinnedDb-plugin,$pinnedDbVersionX2" > modules.txt
131-
fi
132-
./loadModules
133-
cd supertokens-core
134-
git checkout dev-v$coreVersion
135-
cd ../supertokens-plugin-interface
136-
git checkout $currTag
137-
if [[ $currPinnedDb == "sqlite" ]]
138-
then
139-
# shellcheck disable=SC2034
140-
continue=1
141-
else
142-
cd ../supertokens-$currPinnedDb-plugin
143-
git checkout $pinnedDbVersionTag
144-
fi
145-
cd ../
146-
echo $SUPERTOKENS_API_KEY > apiPassword
147-
./startTestingEnv --cicd
138+
update-alternatives --install "/usr/bin/java" "java" "/usr/java/jdk-15.0.1/bin/java" 2
139+
update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/jdk-15.0.1/bin/javac" 2
148140

149-
if [[ $? -ne 0 ]]
150-
then
151-
cat logs/*
152-
cd ../project/
153-
echo "test failed... exiting!"
154-
exit 1
155-
fi
156-
cd ../
157-
rm -rf supertokens-root
141+
coreX=$(cut -d'.' -f1 <<<"$coreVersion")
142+
coreY=$(cut -d'.' -f2 <<<"$coreVersion")
143+
if [[ $currPinnedDb == "sqlite" ]]
144+
then
145+
echo -e "core,$coreX.$coreY\nplugin-interface,$piVersion" > modules.txt
146+
else
147+
echo -e "core,$coreX.$coreY\nplugin-interface,$piVersion\n$currPinnedDb-plugin,$pinnedDbVersionX2" > modules.txt
148+
fi
149+
./loadModules
150+
cd supertokens-core
151+
git checkout dev-v$coreVersion
152+
cd ../supertokens-plugin-interface
153+
git checkout $currTag
154+
if [[ $currPinnedDb == "sqlite" ]]
155+
then
156+
# shellcheck disable=SC2034
157+
continue=1
158+
else
159+
cd ../supertokens-$currPinnedDb-plugin
160+
git checkout $pinnedDbVersionTag
161+
fi
162+
cd ../
163+
echo $SUPERTOKENS_API_KEY > apiPassword
164+
./startTestingEnv --cicd
158165

159-
if [[ $currPinnedDb == "sqlite" ]]
160-
then
161-
# shellcheck disable=SC2034
162-
continue=1
163-
else
164-
curl -o supertokens.zip -s -X GET \
165-
"https://api.supertokens.io/0/app/download?pluginName=$currPinnedDb&os=linux&mode=DEV&binary=FREE&targetCore=$coreVersion&targetPlugin=$pinnedDbVersion" \
166-
-H 'api-version: 0'
167-
unzip supertokens.zip -d .
168-
rm supertokens.zip
169-
cd supertokens
170-
../project/.circleci/testCli.sh
171166
if [[ $? -ne 0 ]]
172167
then
173-
echo "cli testing failed... exiting!"
168+
echo ""
169+
echo ""
170+
echo ""
171+
echo ""
172+
echo ""
173+
echo "===== testing $currPinnedDb with plugin-interface $currVersion FAILED ====="
174+
echo ""
175+
echo ""
176+
echo ""
177+
echo ""
178+
echo ""
179+
180+
cat logs/*
181+
cd ../project/
182+
echo "test failed... exiting!"
174183
exit 1
175184
fi
185+
186+
echo ""
187+
echo ""
188+
echo ""
189+
echo ""
190+
echo ""
191+
echo "===== testing $currPinnedDb with plugin-interface $currVersion SUCCEEDED ====="
192+
echo ""
193+
echo ""
194+
echo ""
195+
echo ""
196+
echo ""
197+
176198
cd ../
177-
fi
199+
rm -rf supertokens-root
200+
201+
if [[ $currPinnedDb == "sqlite" ]]
202+
then
203+
# shellcheck disable=SC2034
204+
continue=1
205+
else
206+
curl -o supertokens.zip -s -X GET \
207+
"https://api.supertokens.io/0/app/download?pluginName=$currPinnedDb&os=linux&mode=DEV&binary=FREE&targetCore=$coreVersion&targetPlugin=$pinnedDbVersion" \
208+
-H 'api-version: 0'
209+
unzip supertokens.zip -d .
210+
rm supertokens.zip
211+
cd supertokens
212+
../project/.circleci/testCli.sh
213+
if [[ $? -ne 0 ]]
214+
then
215+
echo "cli testing failed... exiting!"
216+
exit 1
217+
fi
218+
cd ../
219+
fi
220+
221+
rm -rf supertokens
222+
cd project/.circleci
223+
if [[ $currPinnedDb == "sqlite" ]]
224+
then
225+
# shellcheck disable=SC2034
226+
continue=1
227+
else
228+
./stopDb.sh $currPinnedDb
229+
fi
178230

179-
rm -rf supertokens
180-
cd project/.circleci
181-
if [[ $currPinnedDb == "sqlite" ]]
182-
then
183-
# shellcheck disable=SC2034
184-
continue=1
185-
else
186-
./stopDb.sh $currPinnedDb
187231
fi
232+
188233
done
189234
done 10<pluginInterfaceExactVersionsOutput
190235

191236
if [[ $someTestsRan = "true" ]]
192237
then
193-
echo "calling /core PATCH to make testing passed"
194-
responseStatus=$(curl -s -o /dev/null -w "%{http_code}" -X PATCH \
195-
https://api.supertokens.io/0/core \
196-
-H 'Content-Type: application/json' \
197-
-H 'api-version: 0' \
198-
-d "{
199-
\"password\": \"$SUPERTOKENS_API_KEY\",
200-
\"planType\":\"FREE\",
201-
\"version\":\"$coreVersion\",
202-
\"testPassed\": true
203-
}")
204-
if [ "$responseStatus" -ne "200" ]
205-
then
206-
echo "patch api failed"
207-
exit 1
208-
fi
238+
echo "tests ran successfully"
209239
else
210240
echo "no test ran"
211241
exit 1

.circleci/markPassed.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
coreVersion=$(cat ../build.gradle | grep -e "version =" -e "version=")
2+
3+
while IFS='"' read -ra ADDR; do
4+
counter=0
5+
for i in "${ADDR[@]}"; do
6+
if [ $counter == 1 ]
7+
then
8+
coreVersion=$i
9+
fi
10+
counter=$(($counter+1))
11+
done
12+
done <<< "$coreVersion"
13+
14+
echo "calling /core PATCH to make testing passed"
15+
responseStatus=$(curl -s -o /dev/null -w "%{http_code}" -X PATCH \
16+
https://api.supertokens.io/0/core \
17+
-H 'Content-Type: application/json' \
18+
-H 'api-version: 0' \
19+
-d "{
20+
\"password\": \"$SUPERTOKENS_API_KEY\",
21+
\"planType\":\"FREE\",
22+
\"version\":\"$coreVersion\",
23+
\"testPassed\": true
24+
}")
25+
if [ "$responseStatus" -ne "200" ]
26+
then
27+
echo "patch api failed"
28+
exit 1
29+
fi

.circleci/startDb.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@ case $1 in
33
(cd / && ./runMySQL.sh)
44
mysql -u root --password=root -e "CREATE DATABASE supertokens;"
55
;;
6+
postgresql)
7+
/etc/init.d/postgresql start
8+
sudo -u postgres psql --command "CREATE USER root WITH SUPERUSER PASSWORD 'root';"
9+
createdb
10+
psql -c "create database supertokens;"
611
esac

0 commit comments

Comments
 (0)