@@ -21,14 +21,14 @@ import (
2121 "fmt"
2222 "net"
2323 "reflect"
24+ "runtime"
2425 "strings"
2526 "sync"
2627 "testing"
2728 "time"
2829
2930 "github.com/gogo/protobuf/proto"
3031 "github.com/pkg/errors"
31- "github.com/prometheus/procfs"
3232 "google.golang.org/grpc/codes"
3333 "google.golang.org/grpc/status"
3434)
@@ -366,71 +366,6 @@ func TestClientEOF(t *testing.T) {
366366 }
367367}
368368
369- func TestServerEOF (t * testing.T ) {
370- var (
371- ctx = context .Background ()
372- server = mustServer (t )(NewServer ())
373- addr , listener = newTestListener (t )
374- client , cleanup = newTestClient (t , addr )
375- )
376- defer cleanup ()
377- defer listener .Close ()
378-
379- socketCountBefore := socketCount (t )
380-
381- go server .Serve (ctx , listener )
382-
383- registerTestingService (server , & testingServer {})
384-
385- tp := & testPayload {}
386- // do a regular call
387- if err := client .Call (ctx , serviceName , "Test" , tp , tp ); err != nil {
388- t .Fatalf ("unexpected error during test call: %v" , err )
389- }
390-
391- // close the client, so that server gets EOF
392- if err := client .Close (); err != nil {
393- t .Fatalf ("unexpected error while closing client: %v" , err )
394- }
395-
396- // server should eventually close the client connection
397- maxAttempts := 20
398- for i := 1 ; i <= maxAttempts ; i ++ {
399- socketCountAfter := socketCount (t )
400- if socketCountAfter < socketCountBefore {
401- break
402- }
403- if i == maxAttempts {
404- t .Fatalf ("expected number of open sockets to be less than %d after client close, got %d open sockets" ,
405- socketCountBefore , socketCountAfter )
406- }
407- time .Sleep (100 * time .Millisecond )
408- }
409- }
410-
411- func TestUnixSocketHandshake (t * testing.T ) {
412- var (
413- ctx = context .Background ()
414- server = mustServer (t )(NewServer (WithServerHandshaker (UnixSocketRequireSameUser ())))
415- addr , listener = newTestListener (t )
416- errs = make (chan error , 1 )
417- client , cleanup = newTestClient (t , addr )
418- )
419- defer cleanup ()
420- defer listener .Close ()
421- go func () {
422- errs <- server .Serve (ctx , listener )
423- }()
424-
425- registerTestingService (server , & testingServer {})
426-
427- var tp testPayload
428- // server shutdown, but we still make a call.
429- if err := client .Call (ctx , serviceName , "Test" , & tp , & tp ); err != nil {
430- t .Fatalf ("unexpected error making call: %v" , err )
431- }
432- }
433-
434369func TestServerRequestTimeout (t * testing.T ) {
435370 var (
436371 ctx , cancel = context .WithDeadline (context .Background (), time .Now ().Add (10 * time .Minute ))
@@ -534,38 +469,6 @@ func BenchmarkRoundTrip(b *testing.B) {
534469 }
535470}
536471
537- func BenchmarkRoundTripUnixSocketCreds (b * testing.B ) {
538- // TODO(stevvooe): Right now, there is a 5x performance decrease when using
539- // unix socket credentials. See (UnixCredentialsFunc).Handshake for
540- // details.
541-
542- var (
543- ctx = context .Background ()
544- server = mustServer (b )(NewServer (WithServerHandshaker (UnixSocketRequireSameUser ())))
545- testImpl = & testingServer {}
546- addr , listener = newTestListener (b )
547- client , cleanup = newTestClient (b , addr )
548- tclient = newTestingClient (client )
549- )
550-
551- defer listener .Close ()
552- defer cleanup ()
553-
554- registerTestingService (server , testImpl )
555-
556- go server .Serve (ctx , listener )
557- defer server .Shutdown (ctx )
558-
559- var tp testPayload
560- b .ResetTimer ()
561-
562- for i := 0 ; i < b .N ; i ++ {
563- if _ , err := tclient .Test (ctx , & tp ); err != nil {
564- b .Fatal (err )
565- }
566- }
567- }
568-
569472func checkServerShutdown (t * testing.T , server * Server ) {
570473 t .Helper ()
571474 server .mu .Lock ()
@@ -620,7 +523,13 @@ func newTestClient(t testing.TB, addr string, opts ...ClientOpts) (*Client, func
620523}
621524
622525func newTestListener (t testing.TB ) (string , net.Listener ) {
623- addr := "\x00 " + t .Name ()
526+ var prefix string
527+
528+ // Abstracts sockets are only available on Linux.
529+ if runtime .GOOS == "linux" {
530+ prefix = "\x00 "
531+ }
532+ addr := prefix + t .Name ()
624533 listener , err := net .Listen ("unix" , addr )
625534 if err != nil {
626535 t .Fatal (err )
@@ -639,22 +548,3 @@ func mustServer(t testing.TB) func(server *Server, err error) *Server {
639548 return server
640549 }
641550}
642-
643- func socketCount (t * testing.T ) int {
644- proc , err := procfs .Self ()
645- if err != nil {
646- t .Fatalf ("unexpected error while reading procfs: %v" , err )
647- }
648- fds , err := proc .FileDescriptorTargets ()
649- if err != nil {
650- t .Fatalf ("unexpected error while listing open file descriptors: %v" , err )
651- }
652-
653- sockets := 0
654- for _ , fd := range fds {
655- if strings .Contains (fd , "socket" ) {
656- sockets ++
657- }
658- }
659- return sockets
660- }
0 commit comments