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:
@@ -47,19 +47,24 @@ func (s *Server) Register(name string, handler Handler) {
|
||||
|
||||
// ListenAndServe starts the server.
|
||||
func (s *Server) ListenAndServe(path string) error {
|
||||
tr := trace.New("LocalRPC.Server", path)
|
||||
defer tr.Finish()
|
||||
|
||||
// Previous instances of the server may have shut down uncleanly, leaving
|
||||
// behind the socket file. Remove it just in case.
|
||||
os.Remove(path)
|
||||
|
||||
var err error
|
||||
s.lis, err = net.Listen("unix", path)
|
||||
lis, err := net.Listen("unix", path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return s.Serve(lis)
|
||||
}
|
||||
|
||||
// Serve connections from the given listener.
|
||||
func (s *Server) Serve(lis net.Listener) error {
|
||||
tr := trace.New("LocalRPC.Server", lis.Addr().String())
|
||||
defer tr.Finish()
|
||||
|
||||
s.lis = lis
|
||||
tr.Printf("Listening")
|
||||
for {
|
||||
conn, err := s.lis.Accept()
|
||||
|
||||
Reference in New Issue
Block a user