Skip to content

Commit

Permalink
da: ctx; docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxcanfly committed Mar 14, 2024
1 parent f70db8e commit b3d104c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
20 changes: 16 additions & 4 deletions proxy-jsonrpc/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 4 additions & 0 deletions proxy-jsonrpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit b3d104c

Please sign in to comment.