Add failing test for cleared IP map

We are not clearing the map of seen IP addresses when metrics are
printed, resulting in lower than expected unique IP address counts for
daily metrics.

See https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/issues/40472
This commit is contained in:
Cecylia Bocovich 2025-08-14 14:03:37 -04:00
parent 14b8cde3da
commit 43a35655ad
No known key found for this signature in database
GPG key ID: 009DE379FD9B7B90

View file

@ -1029,5 +1029,43 @@ snowflake-ips-nat-unknown 0
ctx.metrics.printMetrics()
So(buf.String(), ShouldContainSubstring, "client-denied-count 8\nclient-restricted-denied-count 8\nclient-unrestricted-denied-count 0\nclient-snowflake-match-count 0")
})
Convey("that seen IPs map is cleared after each print", func() {
w := httptest.NewRecorder()
data := bytes.NewReader([]byte("{\"Sid\":\"ymbcCMto7KHNGYlp\",\"Version\":\"1.0\",\"AcceptedRelayPattern\":\"snowflake.torproject.net\"}"))
r, err := http.NewRequest("POST", "snowflake.broker/proxy", data)
r.RemoteAddr = "129.97.208.23" //CA geoip
So(err, ShouldBeNil)
go func(i *IPC) {
proxyPolls(i, w, r)
done <- true
}(i)
p := <-ctx.proxyPolls //manually unblock poll
p.offerChannel <- nil
<-done
ctx.metrics.printMetrics()
So(buf.String(), ShouldContainSubstring, "snowflake-ips CA=1")
So(buf.String(), ShouldContainSubstring, "snowflake-ips-total 1")
buf.Reset()
w = httptest.NewRecorder()
data = bytes.NewReader([]byte("{\"Sid\":\"ymbcCMto7KHNGYlp\",\"Version\":\"1.0\",\"AcceptedRelayPattern\":\"snowflake.torproject.net\"}"))
r, err = http.NewRequest("POST", "snowflake.broker/proxy", data)
r.RemoteAddr = "129.97.208.23" //CA geoip
So(err, ShouldBeNil)
go func(i *IPC) {
proxyPolls(i, w, r)
done <- true
}(i)
p = <-ctx.proxyPolls //manually unblock poll
p.offerChannel <- nil
<-done
ctx.metrics.printMetrics()
So(buf.String(), ShouldContainSubstring, "snowflake-ips CA=1")
So(buf.String(), ShouldContainSubstring, "snowflake-ips-total 1")
buf.Reset()
})
})
}