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

Testing setup #142

Merged
merged 17 commits into from
Apr 22, 2020
Merged

Testing setup #142

merged 17 commits into from
Apr 22, 2020

Conversation

promaty
Copy link
Contributor

@promaty promaty commented Apr 22, 2020

Added continuous testing for every commit. This way we can see if all tests are passing while reviewing a PR. Tests are continuously running and creating an image with a :rolling tag. When we finally merge into development/master+tag that rolling image is tagged with :latest/:v* and deployed to k8s.

Currently for testing I just set up a server+postgres with docker-compose and check all localhost api endpoints for correct response. We can add more tests later on.

Tests can also be run locally using docker-compose exec court_server npm run test:server.

This also temporarily fixes the session bug that was blocking front end development.

Copy link
Contributor

@facuspagnuolo facuspagnuolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking really good!

@@ -19,6 +19,7 @@ services:
- "9091:9091" # for debugging metrics
volumes:
- ./packages/server/src:/court-backend/packages/server/src
- ./packages/server/test:/court-backend/packages/server/test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the rationale for adding the test dir here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can update and run tests while developing without rebuilding the container, much faster this way

"morgan": "^1.9.1",
"objection": "^2.1.3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testing dependencies should be devDependencies actually

@@ -25,13 +25,12 @@ export default () => {
})

return session({
store,
key: 'aragonCourtSessionID',
// store, // I disabled this for now because it doesn't work and I will be migrating to Objection in the next PR
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge this PR once we have the whole refactor then

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But front end guys need something functional right now so we can have it working like this (as it was working in my first implementation already)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we simply store a session for the users then? It would be simply doing this I think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh if it's so simple I will fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm in order to make this work your model forces me to use users table but I don't want to touch it right now while we are still actively developing. I would prefer to merge this in memory solution now while I figure out the storage stuff which will still take a day or so.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added your fix, thanks!

resave: false, // Don't force sessions to be saved back to the store even if they didn't change
saveUninitialized: false, // Don't force uninitialized session to be saved to the store
secret: process.env.SESSION_SECRET, // Secret used to generate session IDs
name: 'aragonCourtSessionID', // Cookie name to be used
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -10,6 +10,9 @@ export default app => {
// check user details
app.get( '/users/:address', asyncMiddleware(users.details))

// verify user email using provided token (needs to come before sessions to avoid session authentication)
app.post( '/users/:address/email[:]verify', asyncMiddleware(users.email.verify))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have something similar to what we did with the admin authenticated routes. I prefer being explicit than depend on how we order routes, we can mess it up easily

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm this requires a separate controller, which also requires model, which will depend on storage, I prefer to do this in the next PR

// agent is used to persist authentication cookie across multiple tests
const agent = chai.request.agent(`http://localhost:${serverPort}`);

describe("Server Endpoints", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know #134 hasn't been implemented yet, but let's try to use single quotes for all strings and no semicolons 🙏

chai.use(chaiHttp);

// agent is used to persist authentication cookie across multiple tests
const agent = chai.request.agent(`http://localhost:${serverPort}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proper way to do this with mocha is to use a before statement and an after statement to close it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm before statement doesn't work, agent variable needs to be reachable inside other it scopes. I can only use after to close it.

@@ -10,7 +10,8 @@
"scripts": {
"build": "babel ./src --out-dir ./build --source-maps --copy-files",
"start": "npm run build && ./scripts/db-setup.sh && node ./build",
"start:dev": "./scripts/db-setup.sh && nodemon --ignore ./build --exec babel-node ./src/index.js"
"start:dev": "./scripts/db-setup.sh && nodemon --ignore ./build --exec babel-node ./src/index.js",
"test": "npx mocha test --recursive"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏👏👏👏

export SERVER_IMAGE=$REPO:${GITHUB_SHA}
docker-compose up -d
sleep 10
docker-compose exec -T court_server npm run test:server
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there a way to have a shared testing workflow that both deployments could depend on instead of having it repeated for both?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's a good idea, I will add a shared shell script.

@@ -2,7 +2,10 @@ name: Testnet CI/CD
on:
push:
branches:
- development
# Executes on any non master commit, but release and deploy steps only run on development
# This is useful to see if tests are passing during PR review
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure :)

@promaty promaty requested a review from facuspagnuolo April 22, 2020 19:52
@facuspagnuolo facuspagnuolo merged commit 2789682 into development Apr 22, 2020
@facuspagnuolo facuspagnuolo deleted the testing_setup branch April 22, 2020 20:38
facuspagnuolo added a commit that referenced this pull request Apr 23, 2020
* set up continuous testing for server endpoints

* added ci/cd branch wildcard

* fixed ci/cd files

* fixed conditional ref

* added missing checkout and better docker caching

* run all test actions in a single script

* switch places docker --cahce-from for rolling updates first

* disabled tty for docker-compose exec

* added missing checkout for master ci/cd

* added sleep 10 before running test

* use single quotes and no semicolons

* small fixes

* moved some ci/cd logic into shared shell scripts

* made scripts executable

* added .git to dockerignore for better caching

* cherry pick session storage fix

* re-enabled session storage

Co-authored-by: Facu Spagnuolo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants