-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add DB/Node Restart tests (#1504)
## Relevant issue(s) Resolves #1082 ## Description Adds DB/Node Restart tests. This will be required by Lens (e.g. to make sure migrations are not lost on restart). IIRC I think this also found #1482 (fixed by Fred). --------- Co-authored-by: Fred Carle <fredcarle@users.noreply.github.com>
- Loading branch information
1 parent
db4b853
commit 84f6c8f
Showing
13 changed files
with
461 additions
and
41 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
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
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
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
70 changes: 70 additions & 0 deletions
70
tests/integration/net/state/simple/peer/with_update_restart_test.go
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,70 @@ | ||
// Copyright 2022 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package peer_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/sourcenetwork/immutable" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/tests/integration" | ||
) | ||
|
||
func TestP2PWithSingleDocumentSingleUpdateFromChildAndRestart(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Actions: []any{ | ||
testUtils.RandomNetworkingConfig(), | ||
testUtils.RandomNetworkingConfig(), | ||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type Users { | ||
Name: String | ||
Age: Int | ||
} | ||
`, | ||
}, | ||
testUtils.CreateDoc{ | ||
// Create John on all nodes | ||
Doc: `{ | ||
"Name": "John", | ||
"Age": 21 | ||
}`, | ||
}, | ||
testUtils.ConnectPeers{ | ||
SourceNodeID: 0, | ||
TargetNodeID: 1, | ||
}, | ||
testUtils.Restart{}, | ||
testUtils.UpdateDoc{ | ||
// Update John's Age on the first node only, and allow the value to sync | ||
NodeID: immutable.Some(0), | ||
Doc: `{ | ||
"Age": 60 | ||
}`, | ||
}, | ||
testUtils.WaitForSync{}, | ||
testUtils.Request{ | ||
Request: `query { | ||
Users { | ||
Age | ||
} | ||
}`, | ||
Results: []map[string]any{ | ||
{ | ||
"Age": uint64(60), | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, []string{"Users"}, test) | ||
} |
78 changes: 78 additions & 0 deletions
78
tests/integration/net/state/simple/peer_replicator/with_update_restart_test.go
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,78 @@ | ||
// Copyright 2022 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package peer_replicator_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/sourcenetwork/immutable" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/tests/integration" | ||
) | ||
|
||
func TestP2PPeerReplicatorWithUpdateAndRestart(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Actions: []any{ | ||
testUtils.RandomNetworkingConfig(), | ||
testUtils.RandomNetworkingConfig(), | ||
testUtils.RandomNetworkingConfig(), | ||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type Users { | ||
Name: String | ||
Age: Int | ||
} | ||
`, | ||
}, | ||
testUtils.CreateDoc{ | ||
Doc: `{ | ||
"Name": "John", | ||
"Age": 21 | ||
}`, | ||
}, | ||
testUtils.ConnectPeers{ | ||
SourceNodeID: 1, | ||
TargetNodeID: 0, | ||
}, | ||
testUtils.ConfigureReplicator{ | ||
SourceNodeID: 0, | ||
TargetNodeID: 2, | ||
}, | ||
// We need to wait and ensure that the create events are handled before | ||
// restarting the nodes as otherwise there is no gaurentee which side of | ||
// the restart that the create events are handled, resulting in flaky tests | ||
testUtils.WaitForSync{}, | ||
testUtils.Restart{}, | ||
testUtils.UpdateDoc{ | ||
// Update John's Age on the first node only, and allow the value to sync | ||
NodeID: immutable.Some(0), | ||
Doc: `{ | ||
"Age": 60 | ||
}`, | ||
}, | ||
testUtils.WaitForSync{}, | ||
testUtils.Request{ | ||
Request: `query { | ||
Users { | ||
Age | ||
} | ||
}`, | ||
Results: []map[string]any{ | ||
{ | ||
"Age": uint64(60), | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, []string{"Users"}, test) | ||
} |
64 changes: 64 additions & 0 deletions
64
tests/integration/net/state/simple/replicator/with_create_restart_test.go
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,64 @@ | ||
// Copyright 2022 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package replicator | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/sourcenetwork/immutable" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/tests/integration" | ||
) | ||
|
||
func TestP2POneToOneReplicatorWithRestart(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Actions: []any{ | ||
testUtils.RandomNetworkingConfig(), | ||
testUtils.RandomNetworkingConfig(), | ||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type Users { | ||
Name: String | ||
Age: Int | ||
} | ||
`, | ||
}, | ||
testUtils.ConfigureReplicator{ | ||
SourceNodeID: 0, | ||
TargetNodeID: 1, | ||
}, | ||
testUtils.Restart{}, | ||
testUtils.CreateDoc{ | ||
// Create John on the first (source) node only, and allow the value to sync | ||
NodeID: immutable.Some(0), | ||
Doc: `{ | ||
"Name": "John", | ||
"Age": 21 | ||
}`, | ||
}, | ||
testUtils.WaitForSync{}, | ||
testUtils.Request{ | ||
Request: `query { | ||
Users { | ||
Age | ||
} | ||
}`, | ||
Results: []map[string]any{ | ||
{ | ||
"Age": uint64(21), | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, []string{"Users"}, test) | ||
} |
Oops, something went wrong.