Skip to content

Commit

Permalink
fix: mysql (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc authored Mar 13, 2024
1 parent aacd53d commit 55ec1d9
Show file tree
Hide file tree
Showing 14 changed files with 1,185 additions and 45 deletions.
88 changes: 87 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,73 @@ jobs:
name: running tests
command: (cd .circleci/ && ./doTests.sh)
- slack/status
test-onemillionusers:
docker:
- image: rishabhpoddar/supertokens_core_testing
resource_class: large
steps:
- checkout
- run: echo $'\n[mysqld]\ncharacter_set_server=utf8mb4\nmax_connections=10000' >> /etc/mysql/mysql.cnf
- run:
name: starting mysql
command: |
(cd / && ./runMySQL.sh)
mysql -u root --password=root -e "CREATE DATABASE supertokens;"
mysql -u root --password=root -e "CREATE DATABASE st0;"
mysql -u root --password=root -e "CREATE DATABASE st1;"
mysql -u root --password=root -e "CREATE DATABASE st2;"
mysql -u root --password=root -e "CREATE DATABASE st3;"
mysql -u root --password=root -e "CREATE DATABASE st4;"
mysql -u root --password=root -e "CREATE DATABASE st5;"
mysql -u root --password=root -e "CREATE DATABASE st6;"
mysql -u root --password=root -e "CREATE DATABASE st7;"
mysql -u root --password=root -e "CREATE DATABASE st8;"
mysql -u root --password=root -e "CREATE DATABASE st9;"
mysql -u root --password=root -e "CREATE DATABASE st10;"
mysql -u root --password=root -e "CREATE DATABASE st11;"
mysql -u root --password=root -e "CREATE DATABASE st12;"
mysql -u root --password=root -e "CREATE DATABASE st13;"
mysql -u root --password=root -e "CREATE DATABASE st14;"
mysql -u root --password=root -e "CREATE DATABASE st15;"
mysql -u root --password=root -e "CREATE DATABASE st16;"
mysql -u root --password=root -e "CREATE DATABASE st17;"
mysql -u root --password=root -e "CREATE DATABASE st18;"
mysql -u root --password=root -e "CREATE DATABASE st19;"
mysql -u root --password=root -e "CREATE DATABASE st20;"
mysql -u root --password=root -e "CREATE DATABASE st21;"
mysql -u root --password=root -e "CREATE DATABASE st22;"
mysql -u root --password=root -e "CREATE DATABASE st23;"
mysql -u root --password=root -e "CREATE DATABASE st24;"
mysql -u root --password=root -e "CREATE DATABASE st25;"
mysql -u root --password=root -e "CREATE DATABASE st26;"
mysql -u root --password=root -e "CREATE DATABASE st27;"
mysql -u root --password=root -e "CREATE DATABASE st28;"
mysql -u root --password=root -e "CREATE DATABASE st29;"
mysql -u root --password=root -e "CREATE DATABASE st30;"
mysql -u root --password=root -e "CREATE DATABASE st31;"
mysql -u root --password=root -e "CREATE DATABASE st32;"
mysql -u root --password=root -e "CREATE DATABASE st33;"
mysql -u root --password=root -e "CREATE DATABASE st34;"
mysql -u root --password=root -e "CREATE DATABASE st35;"
mysql -u root --password=root -e "CREATE DATABASE st36;"
mysql -u root --password=root -e "CREATE DATABASE st37;"
mysql -u root --password=root -e "CREATE DATABASE st38;"
mysql -u root --password=root -e "CREATE DATABASE st39;"
mysql -u root --password=root -e "CREATE DATABASE st40;"
mysql -u root --password=root -e "CREATE DATABASE st41;"
mysql -u root --password=root -e "CREATE DATABASE st42;"
mysql -u root --password=root -e "CREATE DATABASE st43;"
mysql -u root --password=root -e "CREATE DATABASE st44;"
mysql -u root --password=root -e "CREATE DATABASE st45;"
mysql -u root --password=root -e "CREATE DATABASE st46;"
mysql -u root --password=root -e "CREATE DATABASE st47;"
mysql -u root --password=root -e "CREATE DATABASE st48;"
mysql -u root --password=root -e "CREATE DATABASE st49;"
mysql -u root --password=root -e "CREATE DATABASE st50;"
- run:
name: running tests
command: (cd .circleci/ && ./doOneMillionUsersTests.sh)
- slack/status

workflows:
version: 2
Expand All @@ -81,4 +148,23 @@ workflows:
tags:
only: /dev-v[0-9]+(\.[0-9]+)*/
branches:
ignore: /.*/
ignore: /.*/
- test-onemillionusers:
context:
- slack-notification
filters:
tags:
only: /dev-v[0-9]+(\.[0-9]+)*/
branches:
ignore: /.*/
- mark-passed:
context:
- slack-notification
filters:
tags:
only: /dev-v[0-9]+(\.[0-9]+)*/
branches:
ignore: /.*/
requires:
- test
- test-onemillionusers
135 changes: 135 additions & 0 deletions .circleci/doOneMillionUsersTests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
function cleanup {
if test -f "pluginInterfaceExactVersionsOutput"; then
rm pluginInterfaceExactVersionsOutput
fi
}

trap cleanup EXIT
cleanup

pluginInterfaceJson=`cat ../pluginInterfaceSupported.json`
pluginInterfaceLength=`echo $pluginInterfaceJson | jq ".versions | length"`
pluginInterfaceArray=`echo $pluginInterfaceJson | jq ".versions"`
echo "got plugin interface relations"

./getPluginInterfaceExactVersions.sh $pluginInterfaceLength "$pluginInterfaceArray"

if [[ $? -ne 0 ]]
then
echo "all plugin interfaces found... failed. exiting!"
exit 1
else
echo "all plugin interfaces found..."
fi

# get plugin version
pluginVersion=`cat ../build.gradle | grep -e "version =" -e "version="`
while IFS='"' read -ra ADDR; do
counter=0
for i in "${ADDR[@]}"; do
if [ $counter == 1 ]
then
pluginVersion=$i
fi
counter=$(($counter+1))
done
done <<< "$pluginVersion"

responseStatus=`curl -s -o /dev/null -w "%{http_code}" -X PUT \
https://api.supertokens.io/0/plugin \
-H 'Content-Type: application/json' \
-H 'api-version: 0' \
-d "{
\"password\": \"$SUPERTOKENS_API_KEY\",
\"planType\":\"FREE\",
\"version\":\"$pluginVersion\",
\"pluginInterfaces\": $pluginInterfaceArray,
\"name\": \"mysql\"
}"`
if [ $responseStatus -ne "200" ]
then
echo "failed plugin PUT API status code: $responseStatus. Exiting!"
exit 1
fi

someTestsRan=false
while read -u 10 line
do
if [[ $line = "" ]]; then
continue
fi
i=0
currTag=`echo $line | jq .tag`
currTag=`echo $currTag | tr -d '"'`

currVersion=`echo $line | jq .version`
currVersion=`echo $currVersion | tr -d '"'`
piX=$(cut -d'.' -f1 <<<"$currVersion")
piY=$(cut -d'.' -f2 <<<"$currVersion")
piVersion="$piX.$piY"

someTestsRan=true

response=`curl -s -X GET \
"https://api.supertokens.io/0/plugin-interface/dependency/core/latest?password=$SUPERTOKENS_API_KEY&planType=FREE&mode=DEV&version=$piVersion" \
-H 'api-version: 0'`
if [[ `echo $response | jq .core` == "null" ]]
then
echo "fetching latest X.Y version for core given plugin-interface X.Y version: $piVersion gave response: $response"
exit 1
fi
coreVersionX2=$(echo $response | jq .core | tr -d '"')

response=`curl -s -X GET \
"https://api.supertokens.io/0/core/latest?password=$SUPERTOKENS_API_KEY&planType=FREE&mode=DEV&version=$coreVersionX2" \
-H 'api-version: 0'`
if [[ `echo $response | jq .tag` == "null" ]]
then
echo "fetching latest X.Y.Z version for core X.Y version: $coreVersionX2 gave response: $response"
exit 1
fi
coreVersionTag=$(echo $response | jq .tag | tr -d '"')

cd ../../
git clone git@github.com:supertokens/supertokens-root.git
cd supertokens-root

update-alternatives --install "/usr/bin/java" "java" "/usr/java/jdk-15.0.1/bin/java" 2
update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/jdk-15.0.1/bin/javac" 2

pluginX=$(cut -d'.' -f1 <<<"$pluginVersion")
pluginY=$(cut -d'.' -f2 <<<"$pluginVersion")
echo -e "core,$coreVersionX2\nplugin-interface,$piVersion\nmysql-plugin,$pluginX.$pluginY" > modules.txt
./loadModules
cd supertokens-core
git checkout $coreVersionTag
cd ../supertokens-plugin-interface
git checkout $currTag
cd ../supertokens-mysql-plugin
git checkout dev-v$pluginVersion
cd ../
echo $SUPERTOKENS_API_KEY > apiPassword
export ONE_MILLION_USERS_TEST=1
./utils/setupTestEnv --cicd
./gradlew :supertokens-postgresql-plugin:test --tests io.supertokens.storage.mysql.test.OneMillionUsersTest

if [[ $? -ne 0 ]]
then
cat logs/*
cd ../project/
echo "test failed... exiting!"
exit 1
fi
cd ../
rm -rf supertokens-root
cd project/.circleci
done 10<pluginInterfaceExactVersionsOutput

if [[ $someTestsRan = "true" ]]
then
echo "all tests ran"
exit 0
else
echo "no test ran"
exit 1
fi
19 changes: 2 additions & 17 deletions .circleci/doTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,8 @@ done 10<pluginInterfaceExactVersionsOutput

if [[ $someTestsRan = "true" ]]
then
echo "calling /core PATCH to make testing passed"
responseStatus=`curl -s -o /dev/null -w "%{http_code}" -X PATCH \
https://api.supertokens.io/0/plugin \
-H 'Content-Type: application/json' \
-H 'api-version: 0' \
-d "{
\"password\": \"$SUPERTOKENS_API_KEY\",
\"planType\":\"FREE\",
\"name\":\"mysql\",
\"version\":\"$pluginVersion\",
\"testPassed\": true
}"`
if [ $responseStatus -ne "200" ]
then
echo "patch api failed"
exit 1
fi
echo "all tests ran"
exit 0
else
echo "no test ran"
exit 1
Expand Down
29 changes: 29 additions & 0 deletions .circleci/markPassed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
pluginVersion=`cat ../build.gradle | grep -e "version =" -e "version="`
while IFS='"' read -ra ADDR; do
counter=0
for i in "${ADDR[@]}"; do
if [ $counter == 1 ]
then
pluginVersion=$i
fi
counter=$(($counter+1))
done
done <<< "$pluginVersion"

echo "calling /core PATCH to make testing passed"
responseStatus=`curl -s -o /dev/null -w "%{http_code}" -X PATCH \
https://api.supertokens.io/0/plugin \
-H 'Content-Type: application/json' \
-H 'api-version: 0' \
-d "{
\"password\": \"$SUPERTOKENS_API_KEY\",
\"planType\":\"FREE\",
\"name\":\"mysql\",
\"version\":\"$pluginVersion\",
\"testPassed\": true
}"`
if [ $responseStatus -ne "200" ]
then
echo "patch api failed"
exit 1
fi
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
- [ ] Issue this PR against the latest non released version branch.
- To know which one it is, run find the latest released tag (`git tag`) in the format `vX.Y.Z`, and then find the latest branch (`git branch --all`) whose `X.Y` is greater than the latest released tag.
- If no such branch exists, then create one from the latest released branch.

- [ ] When adding new recipes, ensure that its performance is being measured in the `OneMillionUsersTest`
## Remaining TODOs for this PR
- [ ] Item1
- [ ] Item2
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id 'java-library'
}

version = "6.0.0"
version = "7.0.0"

repositories {
mavenCentral()
Expand Down
2 changes: 1 addition & 1 deletion pluginInterfaceSupported.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"_comment": "contains a list of plugin interfaces branch names that this core supports",
"versions": [
"5.0"
"6.0"
]
}
5 changes: 3 additions & 2 deletions src/main/java/io/supertokens/storage/mysql/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -2175,10 +2175,11 @@ public boolean updateOrDeleteExternalUserIdInfo(AppIdentifier appIdentifier, Str
}

@Override
public HashMap<String, String> getUserIdMappingForSuperTokensIds(ArrayList<String> userIds)
public HashMap<String, String> getUserIdMappingForSuperTokensIds(AppIdentifier appIdentifier,
ArrayList<String> userIds)
throws StorageQueryException {
try {
return UserIdMappingQueries.getUserIdMappingWithUserIds(this, userIds);
return UserIdMappingQueries.getUserIdMappingWithUserIds(this, appIdentifier, userIds);
} catch (SQLException e) {
throw new StorageQueryException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public static List<String> isEmailVerified_transaction(Start start, Connection s
// calculating the verified emails

HashMap<String, String> supertokensUserIdToExternalUserIdMap = UserIdMappingQueries.getUserIdMappingWithUserIds_Transaction(start,
sqlCon, supertokensUserIds);
sqlCon, appIdentifier, supertokensUserIds);
HashMap<String, String> externalUserIdToSupertokensUserIdMap = new HashMap<>();

List<String> supertokensOrExternalUserIdsToQuery = new ArrayList<>();
Expand Down Expand Up @@ -352,7 +352,7 @@ public static List<String> isEmailVerified(Start start, AppIdentifier appIdentif
// We have external user id stored in the email verification table, so we need to fetch the mapped userids for
// calculating the verified emails
HashMap<String, String> supertokensUserIdToExternalUserIdMap = UserIdMappingQueries.getUserIdMappingWithUserIds(start,
supertokensUserIds);
appIdentifier, supertokensUserIds);
HashMap<String, String> externalUserIdToSupertokensUserIdMap = new HashMap<>();
List<String> supertokensOrExternalUserIdsToQuery = new ArrayList<>();
for (String userId : supertokensUserIds) {
Expand Down
Loading

0 comments on commit 55ec1d9

Please sign in to comment.