go-hep.org/x/hep@v0.38.1/xrootd/ping_test.go (about) 1 // Copyright ©2018 The go-hep Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package xrootd // import "go-hep.org/x/hep/xrootd" 6 7 import ( 8 "context" 9 "testing" 10 ) 11 12 func testSession_Ping(t *testing.T, addr string) { 13 client, err := newSession(context.Background(), addr, "gopher", "", nil) 14 if err != nil { 15 t.Fatalf("could not create client: %v", err) 16 } 17 defer client.Close() 18 19 err = client.Ping(context.Background()) 20 if err != nil { 21 t.Fatalf("invalid ping call: %v", err) 22 } 23 } 24 25 func TestSession_Ping(t *testing.T) { 26 for _, addr := range testClientAddrs { 27 t.Run(addr, func(t *testing.T) { 28 testSession_Ping(t, addr) 29 }) 30 } 31 } 32 33 func BenchmarkSession_Ping(b *testing.B) { 34 for _, addr := range testClientAddrs { 35 b.Run(addr, func(b *testing.B) { 36 benchmarkSession_Ping(b, addr) 37 }) 38 } 39 } 40 41 func benchmarkSession_Ping(b *testing.B, addr string) { 42 client, err := NewClient(context.Background(), addr, "gopher") 43 if err != nil { 44 b.Fatalf("could not create client: %v", err) 45 } 46 b.ResetTimer() 47 for i := 0; i < b.N; i++ { 48 err := client.sessions[client.initialSessionID].Ping(context.Background()) 49 if err != nil { 50 b.Errorf("could not ping: %v", err) 51 } 52 } 53 if err := client.Close(); err != nil { 54 b.Fatalf("could not close client: %v", err) 55 } 56 }