tests: Make test_stop more stable.

It's now based by the browser opening a second page after :stop is run rather
than timing-based, which hopefully should make it run more stable on Travis.
This commit is contained in:
Florian Bruhin 2015-11-23 19:43:11 +01:00
parent d324dd5f70
commit e2da9aa3f8
2 changed files with 30 additions and 6 deletions

View File

@ -154,13 +154,15 @@ Feature: Various utility commands.
Given I have a fresh instance
# We can't use "When I open" because we don't want to wait for load
# finished
When I run :open http://localhost:(port)/custom/redirect-later?delay=2
When I run :open http://localhost:(port)/custom/redirect-later?delay=-1
And I wait for "emitting: cur_load_status_changed('loading') (tab *)" in the log
And I wait 1s
And I run :stop
And I wait 2s
And I open custom/redirect-later-continue in a new tab
And I wait 1s
Then the requests should be:
custom/redirect-later?delay=2
custom/redirect-later-continue
custom/redirect-later?delay=-1
# no request on / because we stopped the redirect
Scenario: :reload

View File

@ -26,6 +26,7 @@ import sys
import time
import signal
import os
import threading
from datetime import datetime
from httpbin.core import app
@ -34,6 +35,9 @@ import cherrypy.wsgiserver
import flask
_redirect_later_event = None
@app.route('/data/<path:path>')
def send_data(path):
if hasattr(sys, 'frozen'):
@ -48,10 +52,28 @@ def send_data(path):
@app.route('/custom/redirect-later')
def redirect_later():
"""302 redirects to / after the given delay."""
"""302 redirects to / after the given delay.
If delay is -1, waits until a request on redirect-later-continue is done.
"""
global _redirect_later_event
args = CaseInsensitiveDict(flask.request.args.items())
time.sleep(int(args.get('delay', '1')))
return flask.redirect('/')
delay = int(args.get('delay', '1'))
if delay == -1:
_redirect_later_event = threading.Event()
_redirect_later_event.wait()
_redirect_later_event = None
else:
time.sleep(delay)
x = flask.redirect('/')
return x
@app.route('/custom/redirect-later-continue')
def redirect_later_continue():
"""Continues a redirect-later with a token."""
_redirect_later_event.set()
return flask.Response(b'Continued redirect.')
@app.after_request