-
-
Save benjirewis/8b088d422788a4beceeb5076652db256 to your computer and use it in GitHub Desktop.
Replace Errors Benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"benjirewis/go-bootstrap/investigations/util" | |
"context" | |
"log" | |
"testing" | |
"go.mongodb.org/mongo-driver/bson" | |
) | |
func BenchmarkReplaceErrors(b *testing.B) { | |
ctx := context.TODO() | |
cli, disc := util.GetClient() | |
defer func() { | |
if err := disc(ctx); err != nil { | |
log.Fatal(err) | |
} | |
}() | |
// Call Watch to create a new change stream. | |
cs, err := cli.Watch(ctx, bson.D{}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
// Call cs.Err() repeatedly to call replaceErrors() on nil. | |
// See the call to replaceErrors on a potentially nil error here: | |
// https://github.com/mongodb/mongo-go-driver/blob/master/mongo/change_stream.go#L541 | |
b.ResetTimer() | |
for i := 0; i < b.N; i++ { | |
err := cs.Err() | |
if err != nil { | |
log.Fatal(err) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment