Skip to content

Commit

Permalink
fix(api): Fix the flaky tempdeck test (#2725)
Browse files Browse the repository at this point in the history
* fix(api): Fix the flaky tempdeck test

The tempdeck driver, when it fails, will sleep and try again. When we’re testing
that, we need to wait a bit - since it’s in a thread - before checking the output.
  • Loading branch information
sfoster1 authored Nov 28, 2018
1 parent fe5cf6a commit f721163
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
# If you send a commmand to the serial comm module and it never sees the
# expected ACK, then it'll eventually time out and return an error

import time


def test_get_temp_deck_temperature():
# Get the curent and target temperatures
Expand Down Expand Up @@ -52,21 +54,33 @@ def test_fail_get_temp_deck_temperature():
temp_deck = TempDeck()
temp_deck.simulating = False

done = False

def _mock_send_command1(self, command, timeout=None):
nonlocal done
done = True
return 'T:none C:90'

temp_deck._send_command = types.MethodType(_mock_send_command1, temp_deck)

temp_deck.update_temperature()
time.sleep(0.25)
while not done:
time.sleep(0.25)

assert temp_deck._temperature == {'current': 90, 'target': None}

def _mock_send_command2(self, command, timeout=None):
nonlocal done
done = True
return 'Tx:none C:1' # Failure premise

temp_deck._send_command = types.MethodType(_mock_send_command2, temp_deck)

done = False
temp_deck.update_temperature()
time.sleep(0.25)
while not done:
time.sleep(0.25)
assert temp_deck._temperature == {'current': 90, 'target': None}


Expand Down

0 comments on commit f721163

Please sign in to comment.