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

Add tests to tips example #833

Merged
merged 15 commits into from
Jul 26, 2022
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
155 changes: 132 additions & 23 deletions .github/workflows/cypress-end-to-end-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ jobs:
run: pip install -e .

- name: 🖋 Create data directory
run: |
cd ~
mkdir mephisto
cd mephisto
mkdir data
run: mkdir -p ~/mephisto/data

- name: 📂 Set the data directory
run: mephisto config core.main_data_directory ~/mephisto/data
Expand Down Expand Up @@ -70,11 +66,8 @@ jobs:
run: pip install -e .

- name: 🖋 Create data directory
run: |
cd ~
mkdir mephisto
cd mephisto
mkdir data
run: mkdir -p ~/mephisto/data

- name: 📂 Set the data directory
run: mephisto config core.main_data_directory ~/mephisto/data

Expand Down Expand Up @@ -118,11 +111,7 @@ jobs:
pip install torch pillow numpy

- name: 🖋 Create data directory
run: |
cd ~
mkdir mephisto
cd mephisto
mkdir data
run: mkdir -p ~/mephisto/data

- name: 📂 Set the data directory
run: mephisto config core.main_data_directory ~/mephisto/data
Expand Down Expand Up @@ -162,16 +151,10 @@ jobs:
node-version: 16

- name: 🤖 Install Mephisto
run: |
pip install -e .
pip install detoxify
run: pip install -e .

- name: 🖋 Create data directory
run: |
cd ~
mkdir mephisto
cd mephisto
mkdir data
run: mkdir -p ~/mephisto/data

- name: 📂 Set the data directory
run: mephisto config core.main_data_directory ~/mephisto/data
Expand All @@ -194,3 +177,129 @@ jobs:
wait-on: "http://localhost:3000/?worker_id=x&assignment_id=1"
command-prefix: yarn dlx
headless: true

static_react_task_with_tips:
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: 🔀 Checking out repo
uses: actions/checkout@v2
- name: 🐍 Installing python
uses: actions/setup-python@v2

- name: 🪨 Setup Node
uses: actions/setup-node@v1
with:
node-version: 16

- name: 🤖 Install Mephisto
run: |
pip install -e .
yes | pip uninstall detoxify

- name: 🖋 Create data directory
run: mkdir -p ~/mephisto/data

- name: 📂 Set the data directory
run: mephisto config core.main_data_directory ~/mephisto/data

- name: 📦 Setting up mephisto-task package
run: |
cd packages/mephisto-task
yarn install
yarn build
npm link

- name: 📦 Setting up mephisto-worker-addons package
run: |
cd packages/mephisto-worker-addons
yarn install
yarn build
npm link

- name: ⌛️ Running pre-submission cypress tests
uses: cypress-io/[email protected]
with:
install: false
browser: chrome
project: ./examples/static_react_task_with_tips/webapp
config-file: ./cypress.config.js
spec: ./examples/static_react_task_with_tips/webapp/cypress/e2e/pre_submission_tests/*
start: python examples/static_react_task_with_tips/run_task.py mephisto.task.force_rebuild=true mephisto.task.post_install_script=link_packages.sh
wait-on: "http://localhost:3000/?worker_id=x&assignment_id=1"
command-prefix: yarn dlx
headless: true

- name: 🔪 Killing the web server
run: |
lsof -nPi :3000
lsof -i -P -n | grep LISTEN | grep python | awk '{print $2}'
kill -INT $(lsof -i -P -n | grep LISTEN | grep python | awk '{print $2}')
echo "killed 1"
sleep 0.5
kill -INT $(lsof -i -P -n | grep LISTEN | grep python | awk '{print $2}')
echo "killed 2"
lsof -i -P -n | grep LISTEN | grep node | awk '{print $2}'
kill -INT $(lsof -i -P -n | grep LISTEN | grep node | awk '{print $2}')
sleep 30
echo "30 seconds passed"

- name: 🥛 Expiring units
run: |
cd mephisto/scripts/local_db/gh_actions
python expire_all_units.py

- name: 📚 Accepting the first submitted tip, accepting the second submitted tip, and rejecting the last submitted tip
run: |
cd mephisto/scripts/local_db
python review_tips_for_task.py << EOF
react-static-task-with-tips
a
5
The tip is very informative
a
0
r
EOF

- name: 🔥 Removing the second accepted tip
run: |
cd mephisto/scripts/local_db
python remove_accepted_tip.py << EOF
react-static-task-with-tips
n
y
EOF

- name: 📖 Reviewing the accepted feedback
run: |
cd mephisto/scripts/local_db
python review_feedback_for_task.py << EOF
react-static-task-with-tips
0
n
u
y
y
EOF
python review_feedback_for_task.py << EOF
react-static-task-with-tips
1
n
u
y
n
EOF

- name: ⌛️ Running post-submission cypress tests
uses: cypress-io/[email protected]
with:
install: false
project: ./examples/static_react_task_with_tips/webapp
config-file: cypress.config.js
spec: ./examples/static_react_task_with_tips/webapp/cypress/e2e/post_submission_tests/*
start: python examples/static_react_task_with_tips/run_task.py mephisto.task.post_install_script=link_packages.sh mephisto.task.force_rebuild=true
wait-on: "http://localhost:3000/?worker_id=x&assignment_id=1"
command-prefix: yarn dlx
browser: chrome
headless: true
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ describe("Loads remote_procedure_toxicity_detection", () => {
cy.get("@textArea").type("I hate bob!");
cy.get("@submitButton").click();
cy.get('[data-cy="loading-spinner"]');
// This timeout is 25000 because the detoxify model takes a good bit of time to run
cy.get('[data-cy="toxicity-alert"]', { timeout: 40000 }).as(
// This timeout is 80000 because the detoxify model takes a good bit of time to run
cy.get('[data-cy="toxicity-alert"]', { timeout: 80000 }).as(
"toxicityAlert"
);
cy.get("@toxicityAlert").contains(
Expand Down
Empty file.
8 changes: 8 additions & 0 deletions examples/static_react_task_with_tips/webapp/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
video: false,

e2e: {
baseUrl: "http://localhost:3000/?worker_id=x&assignment_id=1",
includeShadowDom: true,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { tipClassNamePrefix } from "../../helper";
describe("Checking for tips", () => {
/*
This test is supposed to be ran after running the pre_tip_submission cypress test.
The pre_tip_submission cypress test submits three tips for reviewing.
Before running this test, you should review the tips for static_react_task_with_tips
by running python review_tips_for_task.py.

To pass this test, accept the first tip and reject the other two.
Then run this test and it should pass.

The whole process is gone through in the cypress-end-to-end-tests.yml github actions file.
*/
it("Checks for recently added tip", () => {
cy.visit("/");
cy.get(`.${tipClassNamePrefix}button`).as("tipsButton");
cy.get("@tipsButton").click();

cy.get(`.${tipClassNamePrefix}tip`).eq(-1).as("lastTip");

cy.get("@lastTip").find("h2").as("lastTipHeader");
cy.get("@lastTip").find("p").as("lastTipBody");

cy.get("@lastTipHeader").should(
"have.text",
"🎉 This is my test tip header"
);
cy.get("@lastTipBody").should("have.text", "🎈 This is my test tip body");
});
});
Loading