speedtest-go icon indicating copy to clipboard operation
speedtest-go copied to clipboard

It's confusing that speedtest.New() uses the same GlobalDataManager

Open eric opened this issue 2 years ago • 3 comments
trafficstars

I assumed that each instance of the Speedtest object would have its own state, but it turned out it shared the GlobalDataManager which needed to be reset between runs to be able to give accurate results.

eric avatar Oct 26 '23 23:10 eric

Hi, @eric. You are right. we fixed it and cache records of the last ten tests. reset is still needed.

r3inbowari avatar Oct 27 '23 07:10 r3inbowari

Originally I did not have a Reset() when the test was done (it still is unintuitive to me why I would need a Reset() when I am creating a new object each time) and the numbers I was getting on the second run were 2x the actual numbers. I assumed that speedtest.New() created a new session, but maybe introducing some sort of a session object for each test run would be a simpler way to understand from someone coming to the project for the first time.

eric avatar Oct 27 '23 19:10 eric

Reading through #155 and the examples, I now see that with the change, if I were to throw away the Speedtest object after each run and I am only testing one host, it is not required that I call Reset().

eric avatar Oct 27 '23 19:10 eric