Skip to content

test: Fix environment-dependent flaky assertion in TestTraceInfoOnTimeoutWithSetTimeout - #1184

Merged
jeevatkm merged 1 commit into
go-resty:v3from
Yashh56:fix/test
Jul 19, 2026
Merged

test: Fix environment-dependent flaky assertion in TestTraceInfoOnTimeoutWithSetTimeout#1184
jeevatkm merged 1 commit into
go-resty:v3from
Yashh56:fix/test

Conversation

@Yashh56

@Yashh56 Yashh56 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

close #1166

PR Description

What does this PR do?
Fixes an environment-dependent assertion in TestTraceInfoOnTimeoutWithSetTimeout/timeout_with_very_short_timeout that causes the test suite to fail when run in a network-isolated environment (e.g., docker --network none).

Why is this change necessary?
The test previously asserted assertTrue(t, tr.DNSLookup == 0) under the assumption that a request with an extremely short timeout (1ms) will consistently abort and time out while waiting for DNS resolution. However, in an offline or heavily isolated environment, DNS resolution instantly fails via network-level errors (like connection refused) well before the timeout limit is reached. This records a microscopic but non-zero duration for tr.DNSLookup, causing the strict == 0 assertion to fail.

How does it work?
This PR updates the strict tr.DNSLookup == 0 check to a stronger, mathematically sound, and environment-agnostic invariant:

assertTrue(t, tr.DNSLookup <= tr.TotalTime)

This guarantees that the measured DNS phase duration logically fits within the overall bound of the request's total time—regardless of whether DNS failed instantly or if the context organically timed out.

The subsequent assertions (ConnTime == 0, TLSHandshake == 0, TCPConnTime == 0, ServerTime == 0) remain completely unchanged. This preserves the original and primary intent of the test: ensuring that a request aborting early never successfully progresses to establishing a network connection.

@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.73%. Comparing base (c874c8a) to head (3e76ab4).

Additional details and impacted files
@@           Coverage Diff           @@
##               v3    #1184   +/-   ##
=======================================
  Coverage   99.73%   99.73%           
=======================================
  Files          20       20           
  Lines        4141     4141           
=======================================
  Hits         4130     4130           
  Misses          7        7           
  Partials        4        4           
Flag Coverage Δ
unittests 99.73% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jeevatkm
jeevatkm merged commit ea5b6cf into go-resty:v3 Jul 19, 2026
4 checks passed
@jeevatkm jeevatkm added test-case v3 For resty v3 labels Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test-case v3 For resty v3

Development

Successfully merging this pull request may close these issues.

Test suite fails in network-isolated environment

2 participants