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

test: ci/cd fixing #63

Merged
merged 5 commits into from
Jul 27, 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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ workflows:
tags:
only: /dev-v[0-9]+(\.[0-9]+)*/
branches:
ignore: /.*/
only: /test-cicd\/.*/
21 changes: 16 additions & 5 deletions .circleci/config_continue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ jobs:
docker:
- image: rishabhpoddar/supertokens_website_sdk_testing_node_16
steps:
- run: git config --global url."https://github.com/".insteadOf ssh://[email protected]/ # This makes npm use http instead of ssh (required for node 16)
- checkout
- run: (cd .circleci/ && ./markDevTagAsTestNotPassed.sh)
- run: echo "Testing branch << pipeline.git.branch >>"
- when:
condition:
not:
matches:
pattern: "^test-cicd/.*$"
value: << pipeline.git.branch >>
steps:
- run: git config --global url."https://github.com/".insteadOf ssh://[email protected]/ # This makes npm use http instead of ssh (required for node 16)
- checkout
- run: (cd .circleci/ && ./markDevTagAsTestNotPassed.sh)
test-unit:
docker:
- image: rishabhpoddar/supertokens_flutter_sdk_testing
Expand Down Expand Up @@ -51,6 +59,9 @@ jobs:
echo 'export NVM_DIR="$HOME/.nvm"' >> $BASH_ENV
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> $BASH_ENV
- run: (cd .circleci/ && ./doTests.sh << parameters.fdi-version >>)
- store_artifacts:
path: ../supertokens-root/logs
destination: logfiles
test-success:
docker:
- image: rishabhpoddar/supertokens_website_sdk_testing_node_16
Expand All @@ -69,7 +80,7 @@ workflows:
tags:
only: /dev-v[0-9]+(\.[0-9]+)*/
branches:
ignore: /.*/
only: /test-cicd\/.*/
- test-unit:
requires:
- test-dev-tag-as-not-passed
Expand All @@ -79,7 +90,7 @@ workflows:
tags:
only: /dev-v[0-9]+(\.[0-9]+)*/
branches:
ignore: /.*/
only: /test-cicd\/.*/
matrix:
parameters:
fdi-version: placeholder
Expand Down
41 changes: 28 additions & 13 deletions testHelpers/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,40 @@ let { startST, stopST, killAllST, setupST, cleanST, setKeyValueInConfig, maxVers
let { middleware, errorHandler } = require("supertokens-node/framework/express");
let { verifySession } = require("supertokens-node/recipe/session/framework/express");
const { spawnSync } = require("child_process");
const { debug } = require("console");
const morgan = require("morgan");
let noOfTimesRefreshCalledDuringTest = 0;
let noOfTimesGetSessionCalledDuringTest = 0;
let noOfTimesRefreshAttemptedDuringTest = 0;
let customRefreshHeaderValue = "";
let supertokens_node_version = require("supertokens-node/lib/build/version").version;
let Querier = require("supertokens-node/lib/build/querier").Querier;
let NormalisedURLPath = require("supertokens-node/lib/build/normalisedURLPath").default;
let UserMetaDataRecipeRaw = require("supertokens-node/lib/build/recipe/usermetadata/recipe").default;

let Multitenancy, MultitenancyRaw, multitenancySupported;
try {
MultitenancyRaw = require("supertokens-node/lib/build/recipe/multitenancy/recipe").default;
Multitenancy = require("supertokens-node/lib/build/recipe/multitenancy");
Multitenancy = require("supertokens-node/lib/build/recipe/multitenancy/index");
multitenancySupported = true;
} catch {
} catch (ex) {
console.log({ex});
multitenancySupported = false;
}

let UserMetaDataRecipeRaw;
try {
UserMetaDataRecipeRaw = require("supertokens-node/lib/build/recipe/usermetadata/recipe").default;
} catch {
// Ignored
}

let urlencodedParser = bodyParser.urlencoded({ limit: "20mb", extended: true, parameterLimit: 20000 });
let jsonParser = bodyParser.json({ limit: "20mb" });

let app = express();
app.use(urlencodedParser);
app.use(jsonParser);
app.use(cookieParser());
app.use(morgan(`:date[iso] - :method :url`, { immediate: true }));
app.use(morgan(`:date[iso] - :method :url :status :response-time ms - :res[content-length]`));

let lastSetEnableAntiCSRF = false;
let lastSetEnableJWT = false;
Expand Down Expand Up @@ -207,6 +215,7 @@ app.use(
credentials: true
})
);
app.disable('etag');

app.use(middleware());

Expand All @@ -216,9 +225,7 @@ app.post("/login", async (req, res) => {
let session;

if (multitenancySupported) {
session = await Session.createNewSession(req, res, "public",
accountLinkingSupported ? SuperTokens.convertToRecipeUserId(userId) : userId,
accessTokenPayload);
session = await Session.createNewSession(req, res, "public", accountLinkingSupported ? SuperTokens.convertToRecipeUserId(userId) : userId, accessTokenPayload);
} else {
session = await Session.createNewSession(req, res, userId, accessTokenPayload);
}
Expand All @@ -244,16 +251,18 @@ app.post("/startst", async (req, res) => {
if (enableAntiCsrf !== undefined) {
SuperTokensRaw.reset();
SessionRecipeRaw.reset();
UserMetaDataRecipeRaw.reset();

if (multitenancySupported) {
MultitenancyRaw.reset();
}
if (UserMetaDataRecipeRaw !== undefined) {
UserMetaDataRecipeRaw.reset();
}

SuperTokens.init(getConfig(enableAntiCsrf, enableJWT));
}
let pid = await startST();
res.send(pid + "");
await startST();
res.send("");
});

app.get("/featureFlags", async (req, res) => {
Expand All @@ -273,7 +282,12 @@ app.post("/reinitialiseBackendConfig", async (req, res) => {

SuperTokensRaw.reset();
SessionRecipeRaw.reset();
UserMetaDataRecipeRaw.reset();
if (multitenancySupported) {
MultitenancyRaw.reset();
}
if (UserMetaDataRecipeRaw !== undefined) {
UserMetaDataRecipeRaw.reset();
}
SuperTokens.init(getConfig(lastSetEnableAntiCSRF, currentEnableJWT, jwtPropertyName));

res.send("");
Expand Down Expand Up @@ -575,9 +589,10 @@ app.use("*", async (req, res, next) => {
app.use(errorHandler());

app.use(async (err, req, res, next) => {
console.log({err, stack: new Error().stack });
res.status(500).send(err);
});

let server = http.createServer(app);
// server.listen(process.env.NODE_PORT === undefined ? 8080 : process.env.NODE_PORT, "::");
server.listen(8080, "::");
server.listen(8080, "::");
80 changes: 78 additions & 2 deletions testHelpers/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion testHelpers/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"cookie-parser": "1.4.4",
"cors": "^2.8.5",
"express": "4.17.1",
"morgan": "^1.10.0",
"node-fetch": "^2.7.0",
"supertokens-node": "github:supertokens/supertokens-node"
}
}
}
43 changes: 21 additions & 22 deletions testHelpers/server/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
*/
const { exec } = require("child_process");
let fs = require("fs");
const fetch = require("node-fetch");

module.exports.executeCommand = async function(cmd) {
return new Promise((resolve, reject) => {
console.log("Executing command: " + cmd);
exec(cmd, (err, stdout, stderr) => {

if (err) {
reject(err);
reject({err, stdout, stderr});
return;
}
resolve({ stdout, stderr });
Expand Down Expand Up @@ -97,7 +98,6 @@ module.exports.killAllST = async function() {
module.exports.startST = async function(host = "localhost", port = 9000) {
return new Promise(async (resolve, reject) => {
let installationPath = process.env.INSTALL_PATH;
let pidsBefore = await getListOfPids();
let returned = false;
module.exports
.executeCommand(
Expand All @@ -109,36 +109,35 @@ module.exports.startST = async function(host = "localhost", port = 9000) {
port +
" test_mode"
)
.catch(err => {
.catch(({err, stdout, stderr}) => {
if (!returned) {
console.log("Starting ST failed: java command returned early w/ non-zero exit code");
console.log(err);
console.log(stdout);
console.log(stderr);
returned = true;
reject(err);
}
});
let startTime = Date.now();
let helloResp;
while (Date.now() - startTime < 10000) {
let pidsAfter = await getListOfPids();
if (pidsAfter.length <= pidsBefore.length) {
await new Promise(r => setTimeout(r, 100));
continue;
}
let nonIntersection = pidsAfter.filter(x => !pidsBefore.includes(x));
if (nonIntersection.length !== 1) {
if (!returned) {
returned = true;
reject("something went wrong while starting ST");
}
} else {
if (!returned) {
try {
helloResp = await fetch(`http://${host}:${port}/hello`);
if (helloResp.status === 200) {
console.log("Started ST, it's saying: " + await helloResp.text());
resolve();
returned = true;
resolve(nonIntersection[0]);
return;
}
} catch (ex) {
console.log("Waiting for ST to start, caught exception: " + ex);
// We expect (and ignore) network errors here
}
await new Promise(r => setTimeout(r, 100));
}
if (!returned) {
returned = true;
reject("could not start ST process");
}
console.log(helloResp);
reject("Starting ST process timed out");
});
};

Expand Down
Loading