| 110 | assert minimum <= int(duration) <= self.grace_period |
| 111 | |
| 112 | def stream_request(self, config, connected, early_terminate): |
| 113 | expected_terminate_message = "502 Bad Gateway" |
| 114 | url = config.get_url() + self.sse_endpoint |
| 115 | |
| 116 | with requests.get(url, timeout=5, stream=True) as resp: |
| 117 | with connected: |
| 118 | connected.notifyAll() |
| 119 | lines = 0 |
| 120 | for line in resp.iter_lines(): |
| 121 | if expected_terminate_message.encode() == line: |
| 122 | break |
| 123 | lines += 1 |
| 124 | if early_terminate and lines == 2: |
| 125 | return |
| 126 | # /sse returns count followed by 2 new lines |
| 127 | assert lines >= (self.grace_period * 2) |