-
Notifications
You must be signed in to change notification settings - Fork 561
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: technillogue <technillogue@gmail.com>
- Loading branch information
1 parent
7ef9ff5
commit 4b85361
Showing
4 changed files
with
29 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,38 @@ | ||
import time | ||
|
||
from cog.schema import Status | ||
from cog.schema import PredictionResponse, Status | ||
from cog.server.response_throttler import ResponseThrottler | ||
|
||
processing = PredictionResponse(input={}, status=Status.PROCESSING) | ||
succeeded = PredictionResponse(input={}, status=Status.SUCCEEDED) | ||
|
||
|
||
def test_zero_interval(): | ||
throttler = ResponseThrottler(response_interval=0) | ||
|
||
assert throttler.should_send_response({"status": Status.PROCESSING}) | ||
assert throttler.should_send_response(processing) | ||
throttler.update_last_sent_response_time() | ||
assert throttler.should_send_response({"status": Status.SUCCEEDED}) | ||
assert throttler.should_send_response(succeeded) | ||
|
||
|
||
def test_terminal_status(): | ||
throttler = ResponseThrottler(response_interval=10) | ||
|
||
assert throttler.should_send_response({"status": Status.PROCESSING}) | ||
assert throttler.should_send_response(processing) | ||
throttler.update_last_sent_response_time() | ||
assert not throttler.should_send_response({"status": Status.PROCESSING}) | ||
assert not throttler.should_send_response(processing) | ||
throttler.update_last_sent_response_time() | ||
assert throttler.should_send_response({"status": Status.SUCCEEDED}) | ||
assert throttler.should_send_response(succeeded) | ||
|
||
|
||
def test_nonzero_internal(): | ||
throttler = ResponseThrottler(response_interval=0.2) | ||
|
||
assert throttler.should_send_response({"status": Status.PROCESSING}) | ||
assert throttler.should_send_response(processing) | ||
throttler.update_last_sent_response_time() | ||
assert not throttler.should_send_response({"status": Status.PROCESSING}) | ||
assert not throttler.should_send_response(processing) | ||
throttler.update_last_sent_response_time() | ||
|
||
time.sleep(0.3) | ||
|
||
assert throttler.should_send_response({"status": Status.PROCESSING}) | ||
assert throttler.should_send_response(processing) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters