-
Notifications
You must be signed in to change notification settings - Fork 196
Test: Comprehensive JS event tracking for lifecycle states #10008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 26.eap
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -13,29 +13,31 @@ | |||||
| # See the License for the specific language governing permissions and | ||||||
| # limitations under the License. | ||||||
|
|
||||||
| # Helper script to poll a JS expression via CDP until it matches an expected value. | ||||||
|
|
||||||
| EXPR=$1 | ||||||
| EXPECTED=$2 | ||||||
| PORT=$3 | ||||||
| TIMEOUT=${4:-10} | ||||||
| PORT=${3:-9222} | ||||||
| TIMEOUT=${4:-30} | ||||||
| HOST=${5:-"localhost"} | ||||||
|
|
||||||
| START_TIME=$(date +%s) | ||||||
|
|
||||||
| echo "[WAIT] Waiting for '$EXPR' to be '$EXPECTED' (timeout: ${TIMEOUT}s)..." | ||||||
| echo "[WAIT] Waiting for '$EXPR' to be '$EXPECTED' on $HOST:$PORT (timeout: ${TIMEOUT}s)..." | ||||||
|
|
||||||
| while true; do | ||||||
| RESULT=$(vpython3 cobalt/tools/cdp_js_helper.py --port $PORT "$EXPR" 2>/dev/null) | ||||||
| if [ "$RESULT" == "$EXPECTED" ]; then | ||||||
| RESULT=$(vpython3 cobalt/tools/cdp_js_helper.py --host $HOST --port $PORT "$EXPR" 2>/dev/null) | ||||||
| if [[ "$RESULT" == *"$EXPECTED"* ]]; then | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The transition from an exact match to a substring match (
Suggested change
|
||||||
| END_TIME=$(date +%s) | ||||||
| DURATION=$((END_TIME - START_TIME)) | ||||||
| echo "[WAIT] SUCCESS: '$EXPR' is now '$EXPECTED' (took ${DURATION}s)" | ||||||
| echo "[WAIT] SUCCESS: '$EXPR' matched '$EXPECTED' (took ${DURATION}s)" | ||||||
| exit 0 | ||||||
| fi | ||||||
|
|
||||||
| CURRENT_TIME=$(date +%s) | ||||||
| if [ $((CURRENT_TIME - START_TIME)) -gt $TIMEOUT ]; then | ||||||
| echo "FAILURE: Timeout waiting for $EXPR to be $EXPECTED. Got: $RESULT" | ||||||
| ELAPSED=$((CURRENT_TIME - START_TIME)) | ||||||
| if [ $ELAPSED -ge $TIMEOUT ]; then | ||||||
| echo "FAILURE: Timeout waiting for '$EXPR' to be '$EXPECTED'. Last result: '$RESULT'" | ||||||
| exit 1 | ||||||
| fi | ||||||
| sleep 0.5 | ||||||
| sleep 1 | ||||||
| done | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
asyncio.get_event_loop().time()is generally fine within a running loop, buttime.monotonic()is the standard and more robust way to measure elapsed time for timeouts in Python, as it is independent of the event loop state and clock adjustments.