diff --git a/integration/nwo/common/builder.go b/integration/nwo/common/builder.go index 95cdd9c40..4e329d697 100644 --- a/integration/nwo/common/builder.go +++ b/integration/nwo/common/builder.go @@ -65,7 +65,9 @@ func (s *BuildServer) Serve() { Expect(err).NotTo(HaveOccurred()) s.lis = lis - go utils.IgnoreError(s.server.Serve(lis)) + go utils.IgnoreErrorFunc(func() error { + return s.server.Serve(lis) + }) } func (s *BuildServer) Shutdown(deleteOnStop bool) { diff --git a/integration/nwo/fabric/packager/ccmetadata/validators_test.go b/integration/nwo/fabric/packager/ccmetadata/validators_test.go index 0ba306d9f..4bfbf42e2 100644 --- a/integration/nwo/fabric/packager/ccmetadata/validators_test.go +++ b/integration/nwo/fabric/packager/ccmetadata/validators_test.go @@ -21,7 +21,6 @@ var packageTestDir = filepath.Join(os.TempDir(), "ccmetadata-validator-test") func TestGoodIndexJSON(t *testing.T) { testDir := filepath.Join(packageTestDir, "GoodIndexJSON") - assert.NoError(t, cleanupDir(testDir)) defer utils.IgnoreError(cleanupDir(testDir)) fileName := "META-INF/statedb/couchdb/indexes/myIndex.json" @@ -33,7 +32,6 @@ func TestGoodIndexJSON(t *testing.T) { func TestBadIndexJSON(t *testing.T) { testDir := filepath.Join(packageTestDir, "BadIndexJSON") - assert.NoError(t, cleanupDir(testDir)) defer utils.IgnoreError(cleanupDir(testDir)) fileName := "META-INF/statedb/couchdb/indexes/myIndex.json" @@ -53,7 +51,6 @@ func TestBadIndexJSON(t *testing.T) { func TestIndexWrongLocation(t *testing.T) { testDir := filepath.Join(packageTestDir, "IndexWrongLocation") - assert.NoError(t, cleanupDir(testDir)) defer utils.IgnoreError(cleanupDir(testDir)) fileName := "META-INF/statedb/couchdb/myIndex.json" @@ -72,7 +69,6 @@ func TestIndexWrongLocation(t *testing.T) { func TestInvalidMetadataType(t *testing.T) { testDir := filepath.Join(packageTestDir, "InvalidMetadataType") - assert.NoError(t, cleanupDir(testDir)) defer utils.IgnoreError(cleanupDir(testDir)) fileName := "myIndex.json" @@ -89,7 +85,6 @@ func TestInvalidMetadataType(t *testing.T) { func TestBadMetadataExtension(t *testing.T) { testDir := filepath.Join(packageTestDir, "BadMetadataExtension") - assert.NoError(t, cleanupDir(testDir)) defer utils.IgnoreError(cleanupDir(testDir)) fileName := "myIndex.go" @@ -102,7 +97,6 @@ func TestBadMetadataExtension(t *testing.T) { func TestBadFilePaths(t *testing.T) { testDir := filepath.Join(packageTestDir, "BadMetadataExtension") - assert.NoError(t, cleanupDir(testDir)) defer utils.IgnoreError(cleanupDir(testDir)) // Test bad META-INF @@ -299,7 +293,7 @@ func TestIndexValidationInvalidFields(t *testing.T) { func cleanupDir(dir string) error { // clean up any previous files err := os.RemoveAll(dir) - if err != nil { + if err != nil && !os.IsNotExist(err) { return err } return os.Mkdir(dir, os.ModePerm) diff --git a/platform/common/utils/closer.go b/platform/common/utils/closer.go index 121b27b07..bac69edc2 100644 --- a/platform/common/utils/closer.go +++ b/platform/common/utils/closer.go @@ -6,6 +6,8 @@ SPDX-License-Identifier: Apache-2.0 package utils +import "fmt" + type Closer interface { Close() error } @@ -18,4 +20,11 @@ func CloseMute(closer Closer) { _ = closer.Close() } -func IgnoreError(_ error) {} +func IgnoreError(err error) { + // ignore the error + fmt.Printf("IgnoreError: %v\n", err) +} + +func IgnoreErrorFunc(f func() error) { + _ = f() +} diff --git a/platform/fabric/core/generic/finality/fabric.go b/platform/fabric/core/generic/finality/fabric.go index 9ec9b1217..979b178bd 100644 --- a/platform/fabric/core/generic/finality/fabric.go +++ b/platform/fabric/core/generic/finality/fabric.go @@ -117,7 +117,9 @@ func (d *FabricFinality) IsFinal(txID string, address string) error { return err } eventCh = make(chan delivery.TxEvent, 1) - go utils.IgnoreError(delivery.DeliverReceive(deliverStream, address, txID, eventCh)) + go utils.IgnoreErrorFunc(func() error { + return delivery.DeliverReceive(deliverStream, address, txID, eventCh) + }) committed, _, _, err := delivery.DeliverWaitForResponse(ctx, eventCh, txID) if err != nil { return err diff --git a/platform/orion/core/generic/delivery/delivery.go b/platform/orion/core/generic/delivery/delivery.go index ee0964fef..908c733ab 100644 --- a/platform/orion/core/generic/delivery/delivery.go +++ b/platform/orion/core/generic/delivery/delivery.go @@ -77,7 +77,9 @@ func New(network Network, callback Callback, vault Vault, waitForEventTimeout ti // StartDelivery runs the delivery service in a goroutine func (d *delivery) StartDelivery(ctx context.Context) error { - go utils.IgnoreError(d.Run(ctx)) + go utils.IgnoreErrorFunc(func() error { + return d.Run(ctx) + }) return nil } diff --git a/platform/view/services/grpc/client_test.go b/platform/view/services/grpc/client_test.go index c3b4370be..a37769779 100644 --- a/platform/view/services/grpc/client_test.go +++ b/platform/view/services/grpc/client_test.go @@ -343,7 +343,9 @@ func TestNewConnection(t *testing.T) { } srv := grpc.NewServer(serverOpts...) defer srv.Stop() - go utils.IgnoreError(srv.Serve(lis)) + go utils.IgnoreErrorFunc(func() error { + return srv.Serve(lis) + }) client, err := grpc3.NewGRPCClient(test.config) if err != nil { t.Fatalf("error creating client for test: %v", err) @@ -393,7 +395,9 @@ func TestSetServerRootCAs(t *testing.T) { Certificates: []tls.Certificate{testCerts.serverCert}, }))) defer srv.Stop() - go utils.IgnoreError(srv.Serve(lis)) + go utils.IgnoreErrorFunc(func() error { + return srv.Serve(lis) + }) // initial config should work t.Log("running initial good config") @@ -444,7 +448,7 @@ func TestSetMessageSize(t *testing.T) { } testpb.RegisterEchoServiceServer(srv.Server(), &echoServer{}) defer srv.Stop() - go utils.IgnoreError(srv.Start()) + go utils.IgnoreErrorFunc(srv.Start) var tests = []struct { name string @@ -627,7 +631,7 @@ func TestDynamicClientTLSLoading(t *testing.T) { go func() { defer wg.Done() - utils.IgnoreError(server.Start()) + _ = server.Start() }() var dynamicRootCerts atomic.Value diff --git a/platform/view/services/grpc/server_test.go b/platform/view/services/grpc/server_test.go index 85fd00534..54598d3c0 100644 --- a/platform/view/services/grpc/server_test.go +++ b/platform/view/services/grpc/server_test.go @@ -527,7 +527,7 @@ func TestNewGRPCServer(t *testing.T) { testpb.RegisterEmptyServiceServer(srv.Server(), &emptyServiceServer{}) // start the server - go utils.IgnoreError(srv.Start()) + go utils.IgnoreErrorFunc(srv.Start) defer srv.Stop() // should not be needed @@ -561,7 +561,7 @@ func TestNewGRPCServerFromListener(t *testing.T) { testpb.RegisterEmptyServiceServer(srv.Server(), &emptyServiceServer{}) // start the server - go utils.IgnoreError(srv.Start()) + go utils.IgnoreErrorFunc(srv.Start) defer srv.Stop() // should not be needed @@ -605,7 +605,7 @@ func TestNewSecureGRPCServer(t *testing.T) { testpb.RegisterEmptyServiceServer(srv.Server(), &emptyServiceServer{}) // start the server - go utils.IgnoreError(srv.Start()) + go utils.IgnoreErrorFunc(srv.Start) defer srv.Stop() // should not be needed @@ -689,7 +689,7 @@ func TestVerifyCertificateCallback(t *testing.T) { VerifyCertificate: verifyFunc, }, }) - go utils.IgnoreError(gRPCServer.Start()) + go utils.IgnoreErrorFunc(gRPCServer.Start) defer gRPCServer.Stop() t.Run("Success path", func(t *testing.T) { @@ -736,7 +736,7 @@ func TestWithSignedRootCertificates(t *testing.T) { testpb.RegisterEmptyServiceServer(srv.Server(), &emptyServiceServer{}) // start the server - go utils.IgnoreError(srv.Start()) + go utils.IgnoreErrorFunc(srv.Start) defer srv.Stop() // should not be needed @@ -801,7 +801,7 @@ func TestWithSignedIntermediateCertificates(t *testing.T) { testpb.RegisterEmptyServiceServer(srv.Server(), &emptyServiceServer{}) // start the server - go utils.IgnoreError(srv.Start()) + go utils.IgnoreErrorFunc(srv.Start) defer srv.Stop() // should not be needed @@ -855,7 +855,7 @@ func runMutualAuth(t *testing.T, servers []testServer, trustedClients, unTrusted // register the GRPC test server and start the GRPCServer testpb.RegisterEmptyServiceServer(srv.Server(), &emptyServiceServer{}) - go utils.IgnoreError(srv.Start()) + go utils.IgnoreErrorFunc(srv.Start) defer srv.Stop() // should not be needed but just in case @@ -965,7 +965,7 @@ func TestSetClientRootCAs(t *testing.T) { // register the GRPC test server and start the GRPCServer testpb.RegisterEmptyServiceServer(srv.Server(), &emptyServiceServer{}) - go utils.IgnoreError(srv.Start()) + go utils.IgnoreErrorFunc(srv.Start) defer srv.Stop() // should not be needed but just in case @@ -1058,7 +1058,7 @@ func TestUpdateTLSCert(t *testing.T) { assert.NoError(t, err) testpb.RegisterEmptyServiceServer(srv.Server(), &emptyServiceServer{}) - go utils.IgnoreError(srv.Start()) + go utils.IgnoreErrorFunc(srv.Start) defer srv.Stop() certPool := x509.NewCertPool() @@ -1172,7 +1172,7 @@ func TestCipherSuites(t *testing.T) { testAddress := lis.Addr().String() srv, err := grpc3.NewGRPCServerFromListener(lis, serverConfig) assert.NoError(t, err) - go utils.IgnoreError(srv.Start()) + go utils.IgnoreErrorFunc(srv.Start) for _, test := range tests { test := test @@ -1229,7 +1229,7 @@ func TestServerInterceptors(t *testing.T) { assert.NoError(t, err, "failed to create gRPC server") testpb.RegisterEmptyServiceServer(srv.Server(), &emptyServiceServer{}) defer srv.Stop() - go utils.IgnoreError(srv.Start()) + go utils.IgnoreErrorFunc(srv.Start) _, err = invokeEmptyCall( lis.Addr().String(), diff --git a/platform/view/services/grpc/serverstatshandler_test.go b/platform/view/services/grpc/serverstatshandler_test.go index 8762d4024..f072cbe60 100644 --- a/platform/view/services/grpc/serverstatshandler_test.go +++ b/platform/view/services/grpc/serverstatshandler_test.go @@ -78,7 +78,7 @@ func TestConnMetricsGRPCServer(t *testing.T) { testpb.RegisterEmptyServiceServer(srv.Server(), &emptyServiceServer{}) // start the server - go utils.IgnoreError(srv.Start()) + go utils.IgnoreErrorFunc(srv.Start) defer srv.Stop() // test grpc connection counts diff --git a/platform/view/services/grpc/tlsgen/ca_test.go b/platform/view/services/grpc/tlsgen/ca_test.go index 2f3f34047..ebe5d9fe1 100644 --- a/platform/view/services/grpc/tlsgen/ca_test.go +++ b/platform/view/services/grpc/tlsgen/ca_test.go @@ -45,9 +45,11 @@ func TestTLSCA(t *testing.T) { srv := createTLSService(t, ca, "127.0.0.1") listener, err := net.Listen("tcp", "127.0.0.1:0") assert.NoError(t, err) - go utils.IgnoreError(srv.Serve(listener)) + go utils.IgnoreErrorFunc(func() error { + return srv.Serve(listener) + }) defer srv.Stop() - defer utils.IgnoreError(listener.Close()) + defer utils.IgnoreErrorFunc(listener.Close) probeTLS := func(kp *CertKeyPair) error { cert, err := tls.X509KeyPair(kp.Cert, kp.Key) diff --git a/platform/view/services/metrics/statsd/provider_test.go b/platform/view/services/metrics/statsd/provider_test.go index 584a7e039..b633da655 100644 --- a/platform/view/services/metrics/statsd/provider_test.go +++ b/platform/view/services/metrics/statsd/provider_test.go @@ -52,7 +52,8 @@ var _ = Describe("Provider", func() { for _, alpha := range []string{"x", "y", "z"} { counter.With("alpha", alpha, "beta", "b").Add(1) buf := &bytes.Buffer{} - Expect(s.WriteTo(buf)).To(Succeed()) + _, err := s.WriteTo(buf) + Expect(err).To(Succeed()) Expect(buf.String()).To(Equal(fmt.Sprintf("namespace.subsystem.name.%s.b:%f|c\n", alpha, float64(1)))) } }) @@ -68,7 +69,8 @@ var _ = Describe("Provider", func() { counter.Add(1) buf := &bytes.Buffer{} - Expect(s.WriteTo(buf)).To(Succeed()) + _, err := s.WriteTo(buf) + Expect(err).To(Succeed()) Expect(buf.String()).To(Equal("namespace.subsystem.name:1.000000|c\n")) }) }) @@ -85,7 +87,8 @@ var _ = Describe("Provider", func() { counter.Add(float64(i)) buf := &bytes.Buffer{} - Expect(s.WriteTo(buf)).To(Succeed()) + _, err := s.WriteTo(buf) + Expect(err).To(Succeed()) Expect(buf.String()).To(Equal(fmt.Sprintf("namespace.subsystem.name:%f|c\n", float64(i)))) } }) @@ -123,7 +126,8 @@ var _ = Describe("Provider", func() { for _, alpha := range []string{"x", "y", "z"} { gauge.With("alpha", alpha, "beta", "b").Set(float64(i)) buf := &bytes.Buffer{} - Expect(s.WriteTo(buf)).To(Succeed()) + _, err := s.WriteTo(buf) + Expect(err).To(Succeed()) Expect(buf.String()).To(Equal(fmt.Sprintf("namespace.subsystem.name.%s.b:%f|g\n", alpha, float64(i)))) } } @@ -133,15 +137,16 @@ var _ = Describe("Provider", func() { gauge := provider.NewGauge(gaugeOpts) for _, alpha := range []string{"x", "y", "z"} { - gauge.With("alpha", alpha, "beta", "b").Set(float64(1.0)) + gauge.With("alpha", alpha, "beta", "b").Set(1.0) } for _, alpha := range []string{"x", "y", "z"} { for i := 0; i < 5; i++ { - gauge.With("alpha", alpha, "beta", "b").Add(float64(1.0)) + gauge.With("alpha", alpha, "beta", "b").Add(1.0) } } buf := &bytes.Buffer{} - Expect(s.WriteTo(buf)).To(Succeed()) + _, err := s.WriteTo(buf) + Expect(err).To(Succeed()) Expect(strings.SplitN(buf.String(), "\n", -1)).To(ConsistOf( Equal("namespace.subsystem.name.x.b:6.000000|g"), Equal("namespace.subsystem.name.y.b:6.000000|g"), @@ -161,7 +166,8 @@ var _ = Describe("Provider", func() { gauge.Set(1) buf := &bytes.Buffer{} - Expect(s.WriteTo(buf)).To(Succeed()) + _, err := s.WriteTo(buf) + Expect(err).To(Succeed()) Expect(buf.String()).To(Equal("namespace.subsystem.name:1.000000|g\n")) }) }) @@ -178,7 +184,8 @@ var _ = Describe("Provider", func() { gauge.Add(float64(i)) buf := &bytes.Buffer{} - Expect(s.WriteTo(buf)).To(Succeed()) + _, err := s.WriteTo(buf) + Expect(err).To(Succeed()) Expect(buf.String()).To(Equal(fmt.Sprintf("namespace.subsystem.name:%f|g\n", float64(i)))) } }) @@ -226,7 +233,8 @@ var _ = Describe("Provider", func() { for _, alpha := range []string{"x", "y", "z"} { histogram.With("alpha", alpha, "beta", "b").Observe(float64(i)) buf := &bytes.Buffer{} - Expect(s.WriteTo(buf)).To(Succeed()) + _, err := s.WriteTo(buf) + Expect(err).To(Succeed()) Expect(buf.String()).To(Equal(fmt.Sprintf("namespace.subsystem.name.%s.b:%f|ms\n", alpha, float64(i)))) } } @@ -243,7 +251,8 @@ var _ = Describe("Provider", func() { histogram.Observe(1) buf := &bytes.Buffer{} - Expect(s.WriteTo(buf)).To(Succeed()) + _, err := s.WriteTo(buf) + Expect(err).To(Succeed()) Expect(buf.String()).To(Equal("namespace.subsystem.name:1.000000|ms\n")) }) }) @@ -260,7 +269,8 @@ var _ = Describe("Provider", func() { histogram.Observe(float64(i)) buf := &bytes.Buffer{} - Expect(s.WriteTo(buf)).To(Succeed()) + _, err := s.WriteTo(buf) + Expect(err).To(Succeed()) Expect(buf.String()).To(Equal(fmt.Sprintf("namespace.subsystem.name:%f|ms\n", float64(i)))) } }) diff --git a/platform/view/services/server/web/middleware/chain_test.go b/platform/view/services/server/web/middleware/chain_test.go index c1c4922b4..9d6c69ba2 100644 --- a/platform/view/services/server/web/middleware/chain_test.go +++ b/platform/view/services/server/web/middleware/chain_test.go @@ -29,30 +29,37 @@ var _ = Describe("Chain", func() { BeforeEach(func() { one = func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - Expect(w.Write([]byte("1:before,"))).To(Succeed()) + _, err := w.Write([]byte("1:before,")) + Expect(err).To(Succeed()) next.ServeHTTP(w, r) - Expect(w.Write([]byte("1:after"))).To(Succeed()) + _, err = w.Write([]byte("1:after")) + Expect(err).To(Succeed()) }) } two = func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - Expect(w.Write([]byte("2:before,"))).To(Succeed()) + _, err := w.Write([]byte("2:before,")) + Expect(err).To(Succeed()) next.ServeHTTP(w, r) - Expect(w.Write([]byte("2:after,"))).To(Succeed()) + _, err = w.Write([]byte("2:after,")) + Expect(err).To(Succeed()) }) } three = func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - Expect(w.Write([]byte("3:before,"))).To(Succeed()) + _, err := w.Write([]byte("3:before,")) + Expect(err).To(Succeed()) next.ServeHTTP(w, r) - Expect(w.Write([]byte("3:after,"))).To(Succeed()) + _, err = w.Write([]byte("3:after,")) + Expect(err).To(Succeed()) }) } chain = middleware.NewChain(one, two, three) hello = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) - Expect(w.Write([]byte("Hello!,"))).To(Succeed()) + _, err := w.Write([]byte("Hello!,")) + Expect(err).To(Succeed()) }) req = httptest.NewRequest("GET", "/", nil) diff --git a/platform/view/services/server/web/server.go b/platform/view/services/server/web/server.go index 6257feeb5..167113f1f 100644 --- a/platform/view/services/server/web/server.go +++ b/platform/view/services/server/web/server.go @@ -129,7 +129,9 @@ func (s *Server) Start() error { } s.addr = listener.Addr().String() - go utils.IgnoreError(s.httpServer.Serve(listener)) + go utils.IgnoreErrorFunc(func() error { + return s.httpServer.Serve(listener) + }) return nil }