|
3 | 3 | import logging |
4 | 4 | import os |
5 | 5 | import re |
| 6 | +import time |
6 | 7 | import pytest |
7 | 8 |
|
8 | 9 | from pyhttpd.backport import not_backported |
@@ -157,19 +158,33 @@ def test_h2_008_04(self, env, repeat): |
157 | 158 | url = env.mkurl("https", "test1", f'/data-100m?[0-{count-1}]') |
158 | 159 | r = env.curl_get(url, 5, options=['--http2', '-H', f'Range: bytes=0-{4096}']) |
159 | 160 | assert r.exit_code == 0, f'{r}' |
160 | | - stats = self.get_server_status(env) |
161 | | - # amount reported is larger than (count *4k), the net payload |
162 | | - # but does not exceed an additional 4k |
163 | | - assert (4*count)+1 <= int(stats['Total kBytes']) |
164 | | - assert (4*(count+1))+1 > int(stats['Total kBytes']) |
| 161 | + # The scoreboard is updated as each stream is cleaned up, which can lag |
| 162 | + # the client finishing; poll server-status until the counts settle. |
165 | 163 | # total requests is now at 1 from the start, plus the stat check, |
166 | 164 | # plus the count transfers we did. |
167 | | - assert (2+count) == int(stats['Total Accesses']) |
| 165 | + expected = 2 + count |
| 166 | + # Every extra status request is itself counted, adding one access |
| 167 | + # and the size of its response body. |
| 168 | + polled_kb = 0 |
| 169 | + for _ in range(10): |
| 170 | + stats = self.get_server_status(env) |
| 171 | + accesses = int(stats['Total Accesses']) |
| 172 | + if accesses >= expected: |
| 173 | + break |
| 174 | + expected += 1 |
| 175 | + polled_kb += (self.status_len + 1023) // 1024 |
| 176 | + time.sleep(0.1) |
| 177 | + assert expected == accesses, f'{stats}' |
| 178 | + # amount reported is larger than (count *4k), the net payload |
| 179 | + # but does not exceed an additional 4k |
| 180 | + assert (4*count)+1 <= int(stats['Total kBytes']), f'{stats}' |
| 181 | + assert (4*(count+1))+1 + polled_kb > int(stats['Total kBytes']), f'{stats}' |
168 | 182 |
|
169 | 183 | def get_server_status(self, env): |
170 | 184 | status_url = env.mkurl("https", "test1", '/status?auto') |
171 | 185 | r = env.curl_get(status_url, 5) |
172 | 186 | assert r.exit_code == 0, f'{r}' |
| 187 | + self.status_len = len(r.stdout) |
173 | 188 | stats = {} |
174 | 189 | for line in r.stdout.splitlines(): |
175 | 190 | m = re.match(r'([^:]+): (.*)', line) |
|
0 commit comments