From b3d104ce8be89416d4f287a70ce4414a0c35c898 Mon Sep 17 00:00:00 2001 From: Javed Khan Date: Thu, 14 Mar 2024 12:49:46 -0700 Subject: [PATCH] da: ctx; docs --- proxy-jsonrpc/proxy_test.go | 20 ++++++++++++++++---- proxy-jsonrpc/server.go | 4 ++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/proxy-jsonrpc/proxy_test.go b/proxy-jsonrpc/proxy_test.go index a4a9bf4..da58419 100644 --- a/proxy-jsonrpc/proxy_test.go +++ b/proxy-jsonrpc/proxy_test.go @@ -10,18 +10,30 @@ import ( "github.com/rollkit/go-da/test" ) +const ( + // ServerHost is the listen host for the test JSONRPC server + ServerHost = "localhost" + // ServerPort is the listen port for the test JSONRPC server + ServerPort = "3450" + // ClientURL is the url to dial for the test JSONRPC client + ClientURL = "http://localhost:3450" +) + +// TestProxy runs the go-da DA test suite against the JSONRPC service +// NOTE: This test requires a test JSONRPC service to run on the port +// 3450 which is chosen to be sufficiently distinct from the default port func TestProxy(t *testing.T) { dummy := test.NewDummyDA() - server := proxy.NewServer("localhost", "3450", dummy) - err := server.Start(context.TODO()) + server := proxy.NewServer(ServerHost, ServerPort, dummy) + err := server.Start(context.Background()) require.NoError(t, err) defer func() { - if err := server.Stop(context.TODO()); err != nil { + if err := server.Stop(context.Background()); err != nil { require.NoError(t, err) } }() - client, err := proxy.NewClient(context.TODO(), "http://localhost:3450", "") + client, err := proxy.NewClient(context.Background(), ClientURL, "") require.NoError(t, err) test.RunDATestSuite(t, &client.DA) } diff --git a/proxy-jsonrpc/server.go b/proxy-jsonrpc/server.go index 4f11d14..0e6d9e5 100644 --- a/proxy-jsonrpc/server.go +++ b/proxy-jsonrpc/server.go @@ -47,6 +47,8 @@ func NewServer(address, port string, DA da.DA) *Server { } // Start starts the RPC Server. +// This function can be called multiple times concurrently +// Once started, subsequent calls are a no-op func (s *Server) Start(context.Context) error { couldStart := s.started.CompareAndSwap(false, true) if !couldStart { @@ -65,6 +67,8 @@ func (s *Server) Start(context.Context) error { } // Stop stops the RPC Server. +// This function can be called multiple times concurrently +// Once stopped, subsequent calls are a no-op func (s *Server) Stop(ctx context.Context) error { couldStop := s.started.CompareAndSwap(true, false) if !couldStop {