mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
beeminder: Mostly eliminate nondeterministic failures in test suite.
There's probably follow-up work to do here to eliminate these completely, but this dramatically shrinks the ~1 minute race window that was previously present between import and test function being called.
This commit is contained in:
@@ -7,26 +7,34 @@ from zerver.lib.test_classes import WebhookTestCase
|
|||||||
class BeeminderHookTests(WebhookTestCase):
|
class BeeminderHookTests(WebhookTestCase):
|
||||||
STREAM_NAME = 'beeminder'
|
STREAM_NAME = 'beeminder'
|
||||||
URL_TEMPLATE = u"/api/v1/external/beeminder?api_key={api_key}&email=AARON@zulip.com"
|
URL_TEMPLATE = u"/api/v1/external/beeminder?api_key={api_key}&email=AARON@zulip.com"
|
||||||
|
|
||||||
|
def test_beeminder_derail(self) -> None:
|
||||||
|
# Important: These checks need to be in the test to avoid a race.
|
||||||
|
# TODO: We should mock time.time for these tests
|
||||||
current_time = float(time.time())
|
current_time = float(time.time())
|
||||||
time_delta_in_hours = (float(1517759100) - current_time)/float(3600)
|
time_delta_in_hours = (float(1517759100) - current_time)/float(3600)
|
||||||
|
|
||||||
def test_beeminder_derail(self) -> None:
|
|
||||||
expected_subject = u"beekeeper"
|
expected_subject = u"beekeeper"
|
||||||
expected_message = u"Hello **aaron**! I am the Beeminder bot! :octopus: \n You are going to derail \
|
expected_message = u"Hello **aaron**! I am the Beeminder bot! :octopus: \n You are going to derail \
|
||||||
from goal **gainweight** in **{:0.1f} hours** \n You need **+2 in 7 days (60)** to avoid derailing \n * Pledge: **0$** :relieved:".format(self.time_delta_in_hours)
|
from goal **gainweight** in **{:0.1f} hours** \n You need **+2 in 7 days (60)** to avoid derailing \n * Pledge: **0$** :relieved:".format(time_delta_in_hours)
|
||||||
self.send_and_test_stream_message('derail',
|
self.send_and_test_stream_message('derail',
|
||||||
expected_subject,
|
expected_subject,
|
||||||
expected_message,
|
expected_message,
|
||||||
content_type="application/x-www-form-urlencoded")
|
content_type="application/x-www-form-urlencoded")
|
||||||
|
|
||||||
def test_beeminder_derail_pm(self) -> None:
|
def test_beeminder_derail_pm(self) -> None:
|
||||||
|
# Important: These checks need to be in the test to avoid a race.
|
||||||
|
# TODO: We should mock time.time for these tests
|
||||||
|
current_time = float(time.time())
|
||||||
|
time_delta_in_hours = (float(1517759100) - current_time)/float(3600)
|
||||||
|
|
||||||
self.url = self.build_webhook_url(
|
self.url = self.build_webhook_url(
|
||||||
email="AARON@zulip.com",
|
email="AARON@zulip.com",
|
||||||
username="aaron",
|
username="aaron",
|
||||||
user_ip="127.0.0.1"
|
user_ip="127.0.0.1"
|
||||||
)
|
)
|
||||||
expected_message = u"I am the Beeminder bot! :octopus: \n You are going to derail from \
|
expected_message = u"I am the Beeminder bot! :octopus: \n You are going to derail from \
|
||||||
goal **gainweight** in **{:0.1f} hours** \n You need **+2 in 7 days (60)** to avoid derailing \n * Pledge: **5$**:worried:".format(self.time_delta_in_hours)
|
goal **gainweight** in **{:0.1f} hours** \n You need **+2 in 7 days (60)** to avoid derailing \n * Pledge: **5$**:worried:".format(time_delta_in_hours)
|
||||||
self.send_and_test_private_message('derail_pm',
|
self.send_and_test_private_message('derail_pm',
|
||||||
expected_message,
|
expected_message,
|
||||||
content_type="application/json")
|
content_type="application/json")
|
||||||
|
|||||||
Reference in New Issue
Block a user