-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove manifest versions This also allows us to re-config without re-bootstrap (by restarting the local F3 instance). This is only safe for non-consensus parameters and will be horribly unsafe until we fix #392. Also: - Removes reliance on hashing json, relies on the network name and manual equality checks. - Removes versions. We now expect the version to be explicitly specified in the network name. - Starts message sequence numbers at the current time so we don't need to save them. - Remove the EC from the dynamic manifest provider as it's unused. - Tests. fixes #468 * additional equality test * send updates whenever the manifest changes
- Loading branch information
Showing
10 changed files
with
189 additions
and
105 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package manifest | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
pubsub "github.com/libp2p/go-libp2p-pubsub" | ||
mocknetwork "github.com/libp2p/go-libp2p/p2p/net/mock" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDynamicManifest(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
t.Cleanup(cancel) | ||
|
||
mocknet := mocknetwork.New() | ||
initialManifest := LocalDevnetManifest() | ||
|
||
var ( | ||
sender *ManifestSender | ||
provider *DynamicManifestProvider | ||
) | ||
|
||
{ | ||
host, err := mocknet.GenPeer() | ||
require.NoError(t, err) | ||
t.Cleanup(func() { require.NoError(t, host.Close()) }) | ||
|
||
pubSub, err := pubsub.NewGossipSub(ctx, host, pubsub.WithPeerExchange(true)) | ||
require.NoError(t, err) | ||
sender, err = NewManifestSender(host, pubSub, initialManifest, 10*time.Millisecond) | ||
require.NoError(t, err) | ||
} | ||
|
||
{ | ||
host, err := mocknet.GenPeer() | ||
require.NoError(t, err) | ||
t.Cleanup(func() { require.NoError(t, host.Close()) }) | ||
|
||
pubSub, err := pubsub.NewGossipSub(ctx, host, pubsub.WithPeerExchange(true)) | ||
require.NoError(t, err) | ||
|
||
provider = NewDynamicManifestProvider(initialManifest, pubSub, sender.SenderID()) | ||
} | ||
|
||
mocknet.LinkAll() | ||
mocknet.ConnectAllButSelf() | ||
|
||
waitSender := make(chan error, 1) | ||
senderCtx, cancelSender := context.WithCancel(ctx) | ||
go func() { waitSender <- sender.Run(senderCtx) }() | ||
|
||
require.NoError(t, provider.Start(ctx)) | ||
t.Cleanup(func() { require.NoError(t, provider.Stop(context.Background())) }) | ||
|
||
// Should receive the initial manifest. | ||
require.True(t, initialManifest.Equal(<-provider.ManifestUpdates())) | ||
|
||
// Pausing should send nil. | ||
sender.Pause() | ||
require.Nil(t, <-provider.ManifestUpdates()) | ||
|
||
// Should get the initial manifest again. | ||
sender.Resume() | ||
require.True(t, initialManifest.Equal(<-provider.ManifestUpdates())) | ||
|
||
cancelSender() | ||
require.Nil(t, <-waitSender) | ||
|
||
// Re-start the sender. The client shouldn't see an update. | ||
senderCtx, cancelSender = context.WithCancel(ctx) | ||
go func() { waitSender <- sender.Run(senderCtx) }() | ||
|
||
select { | ||
case <-provider.ManifestUpdates(): | ||
t.Fatal("did not expect a manifest update when restarting manifest sender") | ||
case <-time.After(1 * time.Second): | ||
} | ||
newManifest := *initialManifest | ||
newManifest.NetworkName = "updated-name" | ||
sender.UpdateManifest(&newManifest) | ||
|
||
require.True(t, newManifest.Equal(<-provider.ManifestUpdates())) | ||
|
||
cancelSender() | ||
require.NoError(t, <-waitSender) | ||
} |
Oops, something went wrong.