Repository: quic-go/quic-go
Pull request #4930 (2025-01-26 08:08:39)

utils: add a method to reset the RTTStats for connection migration
Needed for #234.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/quic-go/quic-go/pull/4930?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 83.67%. Comparing base [(`3023083`)](https://app.codecov.io/gh/quic-go/quic-go/commit/302308335cf346ab816b65beeb4e68855311cbce?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go) to head [(`20c7cee`)](https://app.codecov.io/gh/quic-go/quic-go/commit/20c7ceebefc0ec37298da73fd007042b3b532b22?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go).
> Report is 13 commits behind head on master.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #4930      +/-   ##
==========================================
+ Coverage   83.60%   83.67%   +0.08%     
==========================================
  Files         152      149       -3     
  Lines       16253    15926     -327     
==========================================
- Hits        13587    13326     -261     
+ Misses       2138     2094      -44     
+ Partials      528      506      -22     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/quic-go/quic-go/pull/4930?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go).


Patch:
diff --git a/internal/utils/rtt_stats.go b/internal/utils/rtt_stats.go
index 92fec2e2..0efd8354 100644
--- a/internal/utils/rtt_stats.go
+++ b/internal/utils/rtt_stats.go
@@ -108,3 +108,12 @@ func (r *RTTStats) SetInitialRTT(t time.Duration) {
 	r.smoothedRTT = t
 	r.latestRTT = t
 }
+
+func (r *RTTStats) ResetForPathMigration() {
+	r.hasMeasurement = false
+	r.minRTT = 0
+	r.latestRTT = 0
+	r.smoothedRTT = 0
+	r.meanDeviation = 0
+	// max_ack_delay remains valid
+}


Test patch:
diff --git a/internal/utils/rtt_stats_test.go b/internal/utils/rtt_stats_test.go
index b0babc93..816267f5 100644
--- a/internal/utils/rtt_stats_test.go
+++ b/internal/utils/rtt_stats_test.go
@@ -116,3 +116,25 @@ func TestRTTMeasurementAfterRestore(t *testing.T) {
 	require.Equal(t, rtt, rttStats.LatestRTT())
 	require.Equal(t, rtt, rttStats.SmoothedRTT())
 }
+
+func TestRTTStatsResetForPathMigration(t *testing.T) {
+	var rttStats RTTStats
+	rttStats.SetMaxAckDelay(42 * time.Millisecond)
+	rttStats.UpdateRTT(time.Second, 0)
+	rttStats.UpdateRTT(10*time.Second, 0)
+	require.Equal(t, time.Second, rttStats.MinRTT())
+	require.Equal(t, 10*time.Second, rttStats.LatestRTT())
+	require.NotZero(t, rttStats.SmoothedRTT())
+
+	rttStats.ResetForPathMigration()
+	require.Zero(t, rttStats.MinRTT())
+	require.Zero(t, rttStats.LatestRTT())
+	require.Zero(t, rttStats.SmoothedRTT())
+	require.Equal(t, 2*defaultInitialRTT, rttStats.PTO(false))
+	// make sure that max_ack_delay was not reset
+	require.Equal(t, 42*time.Millisecond, rttStats.MaxAckDelay())
+
+	rttStats.UpdateRTT(10*time.Millisecond, 0)
+	require.Equal(t, 10*time.Millisecond, rttStats.SmoothedRTT())
+	require.Equal(t, 10*time.Millisecond, rttStats.LatestRTT())
+}