-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Including a fixture to simplify upcoming gRPC server tests. Also call shimGordianClient where it probably needed to be called, although I did not manually test that it is working as intended.
- Loading branch information
1 parent
2763096
commit 8052b16
Showing
4 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package ggrpctest | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"testing" | ||
|
||
"github.com/gordian-engine/gcosmos/gserver/internal/ggrpc" | ||
"github.com/gordian-engine/gcosmos/internal/copy/gtest" | ||
"github.com/gordian-engine/gordian/tm/tmstore/tmmemstore" | ||
"github.com/stretchr/testify/require" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
// Fixture contains a gRPC server and client, | ||
// ready to use for testing the gRPC services. | ||
type Fixture struct { | ||
Server *ggrpc.GordianGRPC | ||
Client ggrpc.GordianGRPCClient | ||
|
||
// TODO: either pull up the rest of the necessary fields from GRPCServerConfig | ||
// or just outright expose GRPCServerConfig. | ||
FinalizationStore *tmmemstore.FinalizationStore | ||
MirrorStore *tmmemstore.MirrorStore | ||
} | ||
|
||
// NewFixture returns a new fixture whose lifecycle is associated | ||
// with the given context. | ||
// It registers cleanup through t.Cleanup. | ||
// The caller must be sure to defer context cancellation | ||
// in order for the fixture to shut down properly. | ||
func NewFixture(t *testing.T, ctx context.Context) Fixture { | ||
t.Helper() | ||
|
||
log := gtest.NewLogger(t) | ||
|
||
ln, err := net.Listen("tcp", "127.0.0.1:0") | ||
require.NoError(t, err) | ||
t.Cleanup(func() { | ||
_ = ln.Close() | ||
}) | ||
|
||
fs := tmmemstore.NewFinalizationStore() | ||
ms := tmmemstore.NewMirrorStore() | ||
|
||
srv := ggrpc.NewGordianGRPCServer( | ||
ctx, | ||
log.With("sys", "server"), | ||
ggrpc.GRPCServerConfig{ | ||
Listener: ln, | ||
|
||
FinalizationStore: fs, | ||
MirrorStore: ms, | ||
}, | ||
) | ||
t.Cleanup(srv.Wait) | ||
|
||
gc, err := grpc.NewClient( | ||
ln.Addr().String(), | ||
grpc.WithInsecure(), | ||
) | ||
require.NoError(t, err) | ||
c := ggrpc.NewGordianGRPCClient(gc) | ||
|
||
return Fixture{ | ||
Server: srv, | ||
Client: c, | ||
|
||
FinalizationStore: fs, | ||
MirrorStore: ms, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package ggrpc_test | ||
|
||
import ( | ||
context "context" | ||
"testing" | ||
|
||
"github.com/gordian-engine/gcosmos/gserver/internal/ggrpc" | ||
"github.com/gordian-engine/gcosmos/gserver/internal/ggrpc/ggrpctest" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGRPCServer_GetBlocksWatermark(t *testing.T) { | ||
t.Parallel() | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
fx := ggrpctest.NewFixture(t, ctx) | ||
defer cancel() | ||
|
||
require.NoError(t, fx.MirrorStore.SetNetworkHeightRound( | ||
ctx, | ||
10, 1, | ||
9, 3, | ||
)) | ||
|
||
resp, err := fx.Client.GetBlocksWatermark(ctx, new(ggrpc.CurrentBlockRequest)) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, uint64(10), resp.VotingHeight) | ||
require.Equal(t, uint32(1), resp.VotingRound) | ||
require.Equal(t, uint64(9), resp.CommittingHeight) | ||
require.Equal(t, uint32(3), resp.CommittingRound) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters