Skip to content

Commit

Permalink
Embed *Node into nodeState
Browse files Browse the repository at this point in the history
  • Loading branch information
islamaliev committed Nov 13, 2024
1 parent 9876d32 commit e24d2df
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 63 deletions.
8 changes: 4 additions & 4 deletions tests/integration/acp.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func addPolicyACP(
nodeIDs, nodes := getNodesWithIDs(action.NodeID, s.nodes)
for index, node := range nodes {
ctx := getContextWithIdentity(s.ctx, s, action.Identity, nodeIDs[index])
policyResult, err := node.client.AddPolicy(ctx, action.Policy)
policyResult, err := node.DB.AddPolicy(ctx, action.Policy)

expectedErrorRaised := AssertError(s.t, s.testCase.Description, err, action.ExpectedError)
assertExpectedErrorRaised(s.t, s.testCase.Description, action.ExpectedError, expectedErrorRaised)
Expand Down Expand Up @@ -190,7 +190,7 @@ func addDocActorRelationshipACP(
var collectionName string
collectionName, docID = getCollectionAndDocInfo(s, action.CollectionID, action.DocID, nodeID)

exists, err := node.client.AddDocActorRelationship(
exists, err := node.DB.AddDocActorRelationship(
getContextWithIdentity(s.ctx, s, action.RequestorIdentity, nodeID),
collectionName,
docID,
Expand Down Expand Up @@ -276,7 +276,7 @@ func deleteDocActorRelationshipACP(

collectionName, docID := getCollectionAndDocInfo(s, action.CollectionID, action.DocID, nodeID)

deleteDocActorRelationshipResult, err := node.client.DeleteDocActorRelationship(
deleteDocActorRelationshipResult, err := node.DB.DeleteDocActorRelationship(
getContextWithIdentity(s.ctx, s, action.RequestorIdentity, nodeID),
collectionName,
docID,
Expand Down Expand Up @@ -617,7 +617,7 @@ func getNodeAudience(s *state, nodeIndex int) immutable.Option[string] {
if nodeIndex >= len(s.nodes) {
return immutable.None[string]()
}
switch client := s.nodes[nodeIndex].client.(type) {
switch client := s.nodes[nodeIndex].DB.(type) {
case *http.Wrapper:
return immutable.Some(strings.TrimPrefix(client.Host(), "http://"))
case *cli.Wrapper:
Expand Down
5 changes: 2 additions & 3 deletions tests/integration/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func setupNode(s *state, opts ...node.Option) (*nodeState, error) {
if s.isNetworkEnabled {
var addresses []string
for _, node := range s.nodes {
addresses = append(addresses, node.node.Peer.PeerInfo().String())
addresses = append(addresses, node.Peer.PeerInfo().String())
}
netOpts = append(netOpts, net.WithListenAddresses(addresses...))
opts = append(opts, node.WithDisableP2P(false))
Expand All @@ -230,8 +230,7 @@ func setupNode(s *state, opts ...node.Option) (*nodeState, error) {
require.NoError(s.t, err)

st := &nodeState{
client: c,
node: node,
Node: node,
event: eventState,
p2p: newP2PState(),
dbPath: path,
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ const eventTimeout = 1 * time.Second
// waitForNetworkSetupEvents waits for p2p topic completed and
// replicator completed events to be published on the local node event bus.
func waitForNetworkSetupEvents(s *state, nodeID int) {
cols, err := s.nodes[nodeID].client.GetAllP2PCollections(s.ctx)
cols, err := s.nodes[nodeID].DB.GetAllP2PCollections(s.ctx)
require.NoError(s.t, err)

reps, err := s.nodes[nodeID].client.GetAllReplicators(s.ctx)
reps, err := s.nodes[nodeID].DB.GetAllReplicators(s.ctx)
require.NoError(s.t, err)

replicatorEvents := len(reps)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func executeExplainRequest(

_, nodes := getNodesWithIDs(action.NodeID, s.nodes)
for _, node := range nodes {
result := node.client.ExecRequest(
result := node.DB.ExecRequest(
s.ctx,
action.Request,
)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/lens.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ func configureMigration(
) {
_, nodes := getNodesWithIDs(action.NodeID, s.nodes)
for _, node := range nodes {
txn := getTransaction(s, node.client, action.TransactionID, action.ExpectedError)
txn := getTransaction(s, node.DB, action.TransactionID, action.ExpectedError)
ctx := db.SetContextTxn(s.ctx, txn)

err := node.client.SetMigration(ctx, action.LensConfig)
err := node.DB.SetMigration(ctx, action.LensConfig)
expectedErrorRaised := AssertError(s.t, s.testCase.Description, err, action.ExpectedError)

assertExpectedErrorRaised(s.t, s.testCase.Description, action.ExpectedError, expectedErrorRaised)
Expand Down
26 changes: 13 additions & 13 deletions tests/integration/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ func connectPeers(
targetNode := s.nodes[cfg.TargetNodeID]

log.InfoContext(s.ctx, "Connect peers",
corelog.Any("Source", sourceNode.client.PeerInfo()),
corelog.Any("Target", targetNode.client.PeerInfo()))
corelog.Any("Source", sourceNode.DB.PeerInfo()),
corelog.Any("Target", targetNode.DB.PeerInfo()))

err := sourceNode.client.Connect(s.ctx, targetNode.client.PeerInfo())
err := sourceNode.Peer.Connect(s.ctx, targetNode.DB.PeerInfo())
require.NoError(s.t, err)

s.nodes[cfg.SourceNodeID].p2p.connections[cfg.TargetNodeID] = struct{}{}
Expand All @@ -177,8 +177,8 @@ func configureReplicator(
sourceNode := s.nodes[cfg.SourceNodeID]
targetNode := s.nodes[cfg.TargetNodeID]

err := sourceNode.client.SetReplicator(s.ctx, client.ReplicatorParams{
Info: targetNode.client.PeerInfo(),
err := sourceNode.DB.SetReplicator(s.ctx, client.ReplicatorParams{
Info: targetNode.DB.PeerInfo(),
})

expectedErrorRaised := AssertError(s.t, s.testCase.Description, err, cfg.ExpectedError)
Expand All @@ -196,8 +196,8 @@ func deleteReplicator(
sourceNode := s.nodes[cfg.SourceNodeID]
targetNode := s.nodes[cfg.TargetNodeID]

err := sourceNode.client.DeleteReplicator(s.ctx, client.ReplicatorParams{
Info: targetNode.client.PeerInfo(),
err := sourceNode.DB.DeleteReplicator(s.ctx, client.ReplicatorParams{
Info: targetNode.DB.PeerInfo(),
})
require.NoError(s.t, err)
waitForReplicatorDeleteEvent(s, cfg)
Expand All @@ -223,7 +223,7 @@ func subscribeToCollection(
schemaRoots = append(schemaRoots, col.SchemaRoot())
}

err := n.client.AddP2PCollections(s.ctx, schemaRoots)
err := n.DB.AddP2PCollections(s.ctx, schemaRoots)
if err == nil {
waitForSubscribeToCollectionEvent(s, action)
}
Expand Down Expand Up @@ -257,7 +257,7 @@ func unsubscribeToCollection(
schemaRoots = append(schemaRoots, col.SchemaRoot())
}

err := n.client.RemoveP2PCollections(s.ctx, schemaRoots)
err := n.DB.RemoveP2PCollections(s.ctx, schemaRoots)
if err == nil {
waitForUnsubscribeToCollectionEvent(s, action)
}
Expand Down Expand Up @@ -286,7 +286,7 @@ func getAllP2PCollections(
}

n := s.nodes[action.NodeID]
cols, err := n.client.GetAllP2PCollections(s.ctx)
cols, err := n.DB.GetAllP2PCollections(s.ctx)
require.NoError(s.t, err)

assert.Equal(s.t, expectedCollections, cols)
Expand All @@ -300,10 +300,10 @@ func reconnectPeers(s *state) {
targetNode := s.nodes[j]

log.InfoContext(s.ctx, "Connect peers",
corelog.Any("Source", sourceNode.client.PeerInfo()),
corelog.Any("Target", targetNode.client.PeerInfo()))
corelog.Any("Source", sourceNode.DB.PeerInfo()),
corelog.Any("Target", targetNode.DB.PeerInfo()))

err := sourceNode.client.Connect(s.ctx, targetNode.client.PeerInfo())
err := sourceNode.Peer.Connect(s.ctx, targetNode.DB.PeerInfo())
require.NoError(s.t, err)
}
}
Expand Down
5 changes: 1 addition & 4 deletions tests/integration/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/sourcenetwork/defradb/event"
"github.com/sourcenetwork/defradb/net"
"github.com/sourcenetwork/defradb/node"
"github.com/sourcenetwork/defradb/tests/clients"
)

// p2pState contains all p2p related testing state.
Expand Down Expand Up @@ -116,9 +115,7 @@ func newEventState(bus *event.Bus) (*eventState, error) {
// nodeState contains all testing state for a node.
type nodeState struct {
// The node active in this test.
node *node.Node
// The node's client active in this test.
client clients.Client
*node.Node
// event contains all event node subscriptions.
event *eventState
// p2p contains p2p states for the node.
Expand Down
Loading

0 comments on commit e24d2df

Please sign in to comment.