This repository has been archived by the owner on Aug 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 111
Snapshot test #1284
Closed
Closed
Snapshot test #1284
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0f4db1c
swarm/pss: fixed bug in pss.process, test added
gluk256 1c94504
swarm/pss: test case updated
gluk256 243724e
swarm/pss: WaitTillSnapshotRecreated() func added
gluk256 f322700
swarm/pss: snapshot test updated
gluk256 1d7aa22
swarm/pss: WaitTillSnapshotLoaded() fixed
gluk256 4de05a3
swarm/pss: gofmt applied
gluk256 9f1b685
swarm/pss: refactoring, file renamed
gluk256 acc14ba
swarm/pss: input data fixed
gluk256 3105ab6
swarm/pss: race condition fixed
gluk256 26ac00d
swarm/pss: test timeout increased
gluk256 3fcebc1
swarm/pss: eliminated the global variables
gluk256 15ba825
swarm/pss: tests added
gluk256 7657525
swarm/pss: comments added
gluk256 eda75e1
swarm/pss: comment fixed
gluk256 b86a8ac
swarm/pss: refactored according to review
gluk256 144e477
swarm/pss: style fix
gluk256 ec45587
swarm/pss: increased timeout
gluk256 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,3 +144,166 @@ func createSimServiceMap(discovery bool) map[string]ServiceFunc { | |
}, | ||
} | ||
} | ||
|
||
// TestWaitTillSnapshotRecreated tests that we indeed have a network | ||
// configuration specified in the snapshot file, after we wait for it. | ||
// | ||
// First we create a first simulation | ||
// Run it as nodes connected in a ring | ||
// Wait until the network is healthy | ||
// Then we create a snapshot | ||
// With this snapshot we create a new simulation | ||
// Call WaitTillSnapshotRecreated() function and wait until it returns | ||
// Iterate the nodes and check if all the connections are successfully recreated | ||
func TestWaitTillSnapshotRecreated(t *testing.T) { | ||
nolash marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var err error | ||
sim := New(createSimServiceMap(true)) | ||
_, err = sim.AddNodesAndConnectRing(16) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) | ||
defer cancel() | ||
_, err = sim.WaitTillHealthy(ctx) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
originalConnections := sim.getActualConnections() | ||
snap, err := sim.Net.Snapshot() | ||
sim.Close() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
controlSim := New(createSimServiceMap(false)) | ||
defer controlSim.Close() | ||
err = controlSim.Net.Load(snap) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
err = controlSim.WaitTillSnapshotRecreated(ctx, *snap) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
controlConnections := controlSim.getActualConnections() | ||
|
||
for _, c := range originalConnections { | ||
nolash marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if !exist(controlConnections, c) { | ||
t.Fatal("connection was not recreated") | ||
} | ||
} | ||
} | ||
|
||
// exist returns true if val is found in arr | ||
func exist(arr []uint64, val uint64) bool { | ||
nolash marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for _, c := range arr { | ||
if c == val { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func TestRemoveDuplicatesAndSingletons(t *testing.T) { | ||
singletons := []uint64{ | ||
0x3c127c6f6cb026b0, | ||
0x0f45190d72e71fc5, | ||
0xb0184c02449e0bb6, | ||
0xa85c7b84239c54d3, | ||
0xe3b0c44298fc1c14, | ||
0x9afbf4c8996fb924, | ||
0x27ae41e4649b934c, | ||
0xa495991b7852b855, | ||
} | ||
|
||
doubles := []uint64{ | ||
0x1b879f878de7fc7a, | ||
0xc6791470521bdab4, | ||
0xdd34b0ee39bbccc6, | ||
0x4d904fbf0f31da10, | ||
0x6403c2560432c8f8, | ||
0x18954e33cf3ad847, | ||
0x90db00e98dc7a8a6, | ||
0x92886b0dfcc1809b, | ||
} | ||
|
||
var arr []uint64 | ||
arr = append(arr, doubles...) | ||
arr = append(arr, singletons...) | ||
arr = append(arr, doubles...) | ||
arr = removeDuplicatesAndSingletons(arr) | ||
|
||
for _, i := range singletons { | ||
if exist(arr, i) { | ||
t.Fatalf("singleton not removed: %d", i) | ||
} | ||
} | ||
|
||
for _, i := range doubles { | ||
if !exist(arr, i) { | ||
t.Fatalf("wrong value removed: %d", i) | ||
} | ||
} | ||
|
||
for j := 0; j < len(doubles); j++ { | ||
v := doubles[j] + singletons[j] | ||
if exist(arr, v) { | ||
t.Fatalf("non-existing value found, index: %d", j) | ||
} | ||
} | ||
} | ||
|
||
func TestIsAllDeployed(t *testing.T) { | ||
a := []uint64{ | ||
0x3c127c6f6cb026b0, | ||
0x0f45190d72e71fc5, | ||
0xb0184c02449e0bb6, | ||
0xa85c7b84239c54d3, | ||
0xe3b0c44298fc1c14, | ||
0x9afbf4c8996fb924, | ||
0x27ae41e4649b934c, | ||
0xa495991b7852b855, | ||
} | ||
|
||
b := []uint64{ | ||
0x1b879f878de7fc7a, | ||
0xc6791470521bdab4, | ||
0xdd34b0ee39bbccc6, | ||
0x4d904fbf0f31da10, | ||
0x6403c2560432c8f8, | ||
0x18954e33cf3ad847, | ||
0x90db00e98dc7a8a6, | ||
0x92886b0dfcc1809b, | ||
} | ||
|
||
var c []uint64 | ||
c = append(c, a...) | ||
c = append(c, b...) | ||
|
||
if !isAllDeployed(a, c) { | ||
t.Fatal("isAllDeployed failed") | ||
} | ||
|
||
if !isAllDeployed(b, c) { | ||
t.Fatal("isAllDeployed failed") | ||
} | ||
|
||
if isAllDeployed(c, a) { | ||
t.Fatal("isAllDeployed failed: false positive") | ||
} | ||
|
||
if isAllDeployed(c, b) { | ||
t.Fatal("isAllDeployed failed: false positive") | ||
} | ||
|
||
c = c[2:] | ||
|
||
if isAllDeployed(a, c) { | ||
t.Fatal("isAllDeployed failed: false positive") | ||
} | ||
|
||
if !isAllDeployed(b, c) { | ||
t.Fatal("isAllDeployed failed") | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... and the positive? :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this condition remains valid (if i understand your question correctly) |
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideally we should submit kademlia changes as a separate PR tracking as #1298