Skip to content

Commit

Permalink
Speed up build on travis by reducing time.sleep time
Browse files Browse the repository at this point in the history
  • Loading branch information
billyrrr committed Apr 4, 2020
1 parent b968f7a commit a78bcf5
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 22 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ ALLSPHINXOPTS = -b $(BUILDER) -d build/doctrees -D latex_paper_size=$(PAPER) \

# Propagates to child process
export FB_CONFIG_FILENAME = boiler-testing.yaml
export WAIT_TIME = 2 # waits 2 seconds by default for firestore to refresh after change; testing only

.PHONY: help checkout update build html htmlhelp latex text changes linkcheck \
suspicious coverage doctest pydoc-topics htmlview clean dist check serve \
Expand Down
5 changes: 3 additions & 2 deletions examples/binding_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from flask_boiler.view_model import ViewModel
from flask_boiler.domain_model import DomainModel
from google.cloud import firestore
from flask_boiler import testing_utils
from functools import partial

from examples.luggage_models import LuggageItem, Luggages
Expand Down Expand Up @@ -61,7 +62,7 @@
vm.register_listener()

# Takes time to propagate changes
time.sleep(2)
testing_utils._wait(factor=.5)

assert vm.to_dict() == {
"luggages": [
Expand All @@ -87,7 +88,7 @@
# and local copies of a ViewModel should not be used to read
# updated values

time.sleep(2)
testing_utils._wait(factor=.3)

# # Test that the view model now has updated values
assert vm.to_dict() == {
Expand Down
7 changes: 4 additions & 3 deletions examples/distributed_counter_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from flask_boiler.struct import Struct
from flask_boiler.view_mediator_dav import ViewMediatorDAV
from flask_boiler.view_model import ViewModel
from flask_boiler import testing_utils

config = Config(
app_name="flask-boiler-testing",
Expand Down Expand Up @@ -104,7 +105,7 @@ def test_counter():
mediator = CounterMediator(shard_size=10)
mediator.start()

time.sleep(5)
testing_utils._wait()

ref = CTX.db.collection("counters").document("counter_0")

Expand All @@ -126,7 +127,7 @@ def test_increment(CTX):

mediator.start()

time.sleep(3)
testing_utils._wait(factor=.7)

doc_ref = CTX.db.collection("counters").document("counter_0")

Expand All @@ -145,7 +146,7 @@ def test_increment(CTX):
merge=True
)

time.sleep(1)
testing_utils._wait(factor=.3)

assert doc_ref.get().to_dict() == {
"doc_ref": "counters/counter_0",
Expand Down
4 changes: 2 additions & 2 deletions examples/fluttergram/tests/test_delta_dav.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from flask_boiler.view_mediator_dav import ViewMediatorDAV, \
ViewMediatorDeltaDAV
from flask_boiler.view_model import ViewModel
from flask_boiler import view_mediator, utils, schema, fields
from flask_boiler import view_mediator, utils, schema, fields, testing_utils
# Import the fixtures used by fixtures
from tests.fixtures import CTX, setup_app
from .fixtures import users, posts
Expand Down Expand Up @@ -93,7 +93,7 @@ def test_start(users, posts):

mediator.start()

time.sleep(10)
testing_utils._wait(factor=.2)

ref = User._get_collection().document("thomasina").collection("feed") \
.document(posts[0].doc_id)
Expand Down
14 changes: 7 additions & 7 deletions examples/meeting_room/tests/test_dav.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
ViewMediatorDeltaDAV
from flask_boiler.view_model import ViewModel
from ..views import meeting_session_ops
from flask_boiler import view_mediator, utils
from flask_boiler import view_mediator, utils, testing_utils
# Import the fixtures used by fixtures
from tests.fixtures import CTX, setup_app
from .fixtures import users, tickets, location, meeting
Expand Down Expand Up @@ -101,7 +101,7 @@ def test_start(users, tickets, location, meeting):

mediator.start()

time.sleep(5)
testing_utils._wait(factor=.7)

ref = Context.db.collection("users").document(users[0].doc_id) \
.collection(MeetingSessionDAV.__name__).document(meeting.doc_id)
Expand Down Expand Up @@ -145,7 +145,7 @@ def test_mutate(users, tickets, location, meeting):

mediator.start()

time.sleep(5)
testing_utils._wait(factor=.7)

ref = Context.db.collection("users").document(users[0].doc_id) \
.collection(MeetingSessionDAV.__name__).document(meeting.doc_id)
Expand Down Expand Up @@ -185,7 +185,7 @@ def test_mutate(users, tickets, location, meeting):
)
)

time.sleep(5)
testing_utils._wait(factor=.7)

m = Meeting.get(doc_id="meeting_1")
assert m.status == "closed"
Expand Down Expand Up @@ -231,7 +231,7 @@ def test_domain_model_changes(users, tickets, location, meeting):

mediator.start()

time.sleep(5)
testing_utils._wait(factor=.7)
#
ref = Context.db.collection("users").document(users[0].doc_id) \
.collection(MeetingSessionDAV.__name__).document(meeting.doc_id)
Expand All @@ -257,7 +257,7 @@ def test_domain_model_changes(users, tickets, location, meeting):
tickets[0].attendance = False
tickets[0].save()

time.sleep(5)
testing_utils._wait(factor=.7)
#
"""
Expect the document to be updated to exclude Tijuana Furlong from a
Expand Down Expand Up @@ -443,7 +443,7 @@ def test_mutation(users, tickets, location, meeting):
"lastName": "Manes-Kennedy"
})

time.sleep(3)
testing_utils._wait(factor=.7)

updated_user = User.get(doc_id=user_id)

Expand Down
8 changes: 4 additions & 4 deletions examples/meeting_room/tests/test_view_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from examples.meeting_room.view_models.meeting_session import \
MeetingSessionMutation
from ..views import meeting_session_ops
from flask_boiler import view_mediator
from flask_boiler import view_mediator, testing_utils
from .. import view_models
# Import the fixtures used by fixtures
from tests.fixtures import CTX, setup_app
Expand Down Expand Up @@ -50,7 +50,7 @@ def test_view(users, tickets, location, meeting, setup_app):
list_get_view=meeting_session_ops.ListGet
)

time.sleep(2) # TODO: delete after implementing sync
testing_utils._wait(factor=.7)

test_client = app.test_client()

Expand Down Expand Up @@ -110,7 +110,7 @@ def test_view(users, tickets, location, meeting, setup_app):
"inSession": False
})

time.sleep(3)
testing_utils._wait(factor=.7)

res = test_client.get(
path='meeting_sessions/meeting_1')
Expand Down Expand Up @@ -176,7 +176,7 @@ def test_view_model_update(users, tickets, location, meeting):
tickets[0].attendance = False
tickets[0].save()

time.sleep(5)
testing_utils._wait()

assert meeting_session._export_as_view_dict() == {'inSession': True,
'longitude': -117.242929,
Expand Down
25 changes: 25 additions & 0 deletions flask_boiler/testing_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import time
DEFAULT_WAIT_TIME = 5

import logging
root_log = logging.getLogger()
stats = {"total": 0}

try:
import os
wt = os.getenv("WAIT_TIME")
if wt is not None:
DEFAULT_WAIT_TIME = wt
except Exception as e:
"""
TODO: find the best practice to handle a "black swan" error
"""
raise e


def _wait(secs=DEFAULT_WAIT_TIME, factor=1):
secs = int(secs * factor)
time.sleep(secs)
stats["total"] += secs
logging.debug(msg=f"waited for {secs} seconds, "
f"a total of {stats['total']} seconds in this session")
6 changes: 3 additions & 3 deletions tests/test_view_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from google.cloud.firestore import DocumentReference

from examples.luggage_models import LuggageItem, Luggages
from flask_boiler import fields
from flask_boiler import fields, testing_utils
from flask_boiler.schema import Schema
from flask_boiler.domain_model import DomainModel
from flask_boiler.view_model import ViewModel
Expand Down Expand Up @@ -94,7 +94,7 @@ def test_binding(CTX):
vm.register_listener()

# Takes time to propagate changes
time.sleep(2)
testing_utils._wait(factor=.7)

assert vm.to_dict() == {
"luggages": [
Expand All @@ -120,7 +120,7 @@ def test_binding(CTX):
# and local copies of a ViewModel should not be used to read
# updated values

time.sleep(2)
testing_utils._wait(factor=.7)

# # Test that the view model now has updated values
assert vm.to_dict() == {
Expand Down
4 changes: 3 additions & 1 deletion tests/test_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import pytest
from unittest.mock import MagicMock, patch

from flask_boiler import testing_utils
from flask_boiler.view_mediator_websocket import ViewMediatorWebsocket
from .color_fixtures import Color, PaletteViewModel, rainbow_vm, color_refs
from .fixtures import setup_app, CTX
Expand Down Expand Up @@ -46,7 +48,7 @@ class Demo(ViewMediatorWebsocket):

color_refs[0].update({"name": "cyan"})

time.sleep(1)
testing_utils._wait(factor=.7)

assert client.get_received(namespace="/palette") == [{'name': 'updated', 'args': [{'colors': ['cyan', 'magenta', 'yellow'], 'rainbowName': 'cyan-magenta-yellow'}], 'namespace': '/palette'}]

0 comments on commit a78bcf5

Please sign in to comment.