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

Wait for PostHog to start serving requests before running cypress #920

Merged
merged 4 commits into from
Jun 4, 2020
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
6 changes: 3 additions & 3 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
with:
node-version: 12
- run: yarn install

- name: Prepare server
run: docker-compose -f docker-compose.e2e.yml up -d
- name: Check running containers
Expand All @@ -21,5 +21,5 @@ jobs:

- name: Cypress run
run: |
sleep 60
yarn run cypress run --config-file cypress.json
python3 cypress/wait.py
yarn run cypress run --config-file cypress.json
28 changes: 28 additions & 0 deletions cypress/wait.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import datetime
import http.client
import time


def main():
print("Waiting to run tests until PostHog is up and serving requests")
booted = False
ts = datetime.datetime.now()
while not booted and (datetime.datetime.now() - ts).seconds < 240:
try:
conn = http.client.HTTPConnection("127.0.0.1", 8000)
conn.request("GET", "/_health/")
r = conn.getresponse()
if r.status == 200:
booted = True
print("PostHog is alive! Proceeding")
continue
else:
# recieved not 200 from PostHog, but service is up
print("PostHog is still booting. Sleeping for 1 second")
except:
print("PostHog is still booting. Sleeping for 1 second")
time.sleep(1)


if __name__ == "__main__":
main()