mirror of
https://blitiri.com.ar/repos/chasquid
synced 2026-10-29 15:02:30 +00:00
test: Use modern testing features instead of custom helpers
Many of our tests rely on helpers that predate features which are now available in the standard library. This patch replaces them with the standard equivalents: - MustTempDir/RemoveIfOk -> t.ArtifactDir() or t.TempDir() (depending on whether it is useful to keep the data on request). - GetFreePort + waitForServer -> opening the listeners before starting the servers. To support this, localrpc.Server gains a Serve method. We may re-introduce these in the future if more use cases appear. - WaitFor and real-time timing checks -> testing/synctest. - context.Background() -> t.Context(). - Benchmark b.N loops -> b.Loop(). - reflect.DeepEqual -> cmp.Diff, and proto.Equal for protobufs.
This commit is contained in:
@@ -39,7 +39,7 @@ func BenchmarkTrace_10000(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkNewAndFinish(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
for b.Loop() {
|
||||
tr := New("bench", "test")
|
||||
tr.Finish()
|
||||
}
|
||||
@@ -48,8 +48,7 @@ func BenchmarkNewAndFinish(b *testing.B) {
|
||||
func BenchmarkPrintf(b *testing.B) {
|
||||
tr := New("bench", "test")
|
||||
defer tr.Finish()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
for b.Loop() {
|
||||
// Keep this without any formatting, so we measure our code instead of
|
||||
// the performance of fmt.Sprintf.
|
||||
tr.Printf("this is printf")
|
||||
|
||||
Reference in New Issue
Block a user