ipfs-cluster/pnet_test.go

88 lines
2.4 KiB
Go
Raw Normal View History

2017-06-30 00:40:06 +00:00
package ipfscluster
import (
"context"
"testing"
)
2017-06-30 00:40:06 +00:00
func TestClusterSecretFormat(t *testing.T) {
2017-07-20 23:11:40 +00:00
goodSecret := "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
emptySecret := ""
tooShort := "0123456789abcdef"
tooLong := "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0"
unsupportedChars := "0123456789abcdef0123456789!!!!!!0123456789abcdef0123456789abcdef"
_, err := DecodeClusterSecret(goodSecret)
if err != nil {
2017-07-20 23:11:40 +00:00
t.Fatal("Failed to decode well-formatted secret.")
}
decodedEmptySecret, err := DecodeClusterSecret(emptySecret)
if decodedEmptySecret != nil || err != nil {
2017-07-20 23:11:40 +00:00
t.Fatal("Unsuspected output of decoding empty secret.")
}
_, err = DecodeClusterSecret(tooShort)
if err == nil {
2017-07-20 23:11:40 +00:00
t.Fatal("Successfully decoded secret that should haved failed (too short).")
}
_, err = DecodeClusterSecret(tooLong)
if err == nil {
2017-07-20 23:11:40 +00:00
t.Fatal("Successfully decoded secret that should haved failed (too long).")
}
_, err = DecodeClusterSecret(unsupportedChars)
if err == nil {
2017-07-20 23:11:40 +00:00
t.Fatal("Successfully decoded secret that should haved failed (unsupported chars).")
}
}
2017-06-30 00:40:06 +00:00
func TestSimplePNet(t *testing.T) {
ctx := context.Background()
Consensus: add new "crdt" consensus component This adds a new "crdt" consensus component using go-ds-crdt. This implies several refactors to fully make cluster consensus-component independent: * Delete mapstate and fully adopt dsstate (after people have migrated). * Return errors from state methods rather than ignoring them. * Add a new "datastore" modules so that we can configure datastores in the main configuration like other components. * Let the consensus components fully define the "state.State". Thus, they do not receive the state, they receive the storage where we put the state (a go-datastore). * Allow to customize how the monitor component obtains Peers() (the current peerset), including avoiding using the current peerset. At the moment the crdt consensus uses the monitoring component to define the current peerset. Therefore the monitor component cannot rely on the consensus component to produce a peerset. * Re-factor/re-implementation of "ipfs-cluster-service state" operations. Includes the dissapearance of the "migrate" one. The CRDT consensus component defines creates a crdt-datastore (with ipfs-lite) and uses it to intitialize a dssate. Thus the crdt-store is elegantly wrapped. Any modifications to the state get automatically replicated to other peers. We store all the CRDT DAG blocks in the local datastore. The consensus components only expose a ReadOnly state, as any modifications to the shared state should happen through them. DHT and PubSub facilities must now be created outside of Cluster and passed in so they can be re-used by different components.
2019-02-20 14:24:25 +00:00
clusters, mocks, boot := peerManagerClusters(t)
defer cleanRaft()
defer shutdownClusters(t, clusters, mocks)
Consensus: add new "crdt" consensus component This adds a new "crdt" consensus component using go-ds-crdt. This implies several refactors to fully make cluster consensus-component independent: * Delete mapstate and fully adopt dsstate (after people have migrated). * Return errors from state methods rather than ignoring them. * Add a new "datastore" modules so that we can configure datastores in the main configuration like other components. * Let the consensus components fully define the "state.State". Thus, they do not receive the state, they receive the storage where we put the state (a go-datastore). * Allow to customize how the monitor component obtains Peers() (the current peerset), including avoiding using the current peerset. At the moment the crdt consensus uses the monitoring component to define the current peerset. Therefore the monitor component cannot rely on the consensus component to produce a peerset. * Re-factor/re-implementation of "ipfs-cluster-service state" operations. Includes the dissapearance of the "migrate" one. The CRDT consensus component defines creates a crdt-datastore (with ipfs-lite) and uses it to intitialize a dssate. Thus the crdt-store is elegantly wrapped. Any modifications to the state get automatically replicated to other peers. We store all the CRDT DAG blocks in the local datastore. The consensus components only expose a ReadOnly state, as any modifications to the shared state should happen through them. DHT and PubSub facilities must now be created outside of Cluster and passed in so they can be re-used by different components.
2019-02-20 14:24:25 +00:00
defer boot.Close()
2017-06-30 00:40:06 +00:00
if len(clusters) < 2 {
t.Skip("need at least 2 nodes for this test")
}
_, err := clusters[0].PeerAdd(ctx, clusters[1].id)
if err != nil {
t.Fatal(err)
}
ttlDelay()
2017-06-30 00:40:06 +00:00
if len(clusters[0].Peers(ctx)) != len(clusters[1].Peers(ctx)) {
t.Fatal("Expected same number of peers")
}
if len(clusters[0].Peers(ctx)) != 2 {
t.Fatal("Expected 2 peers")
}
2017-06-30 00:40:06 +00:00
}
// // Adds one minute to tests. Disabled for the moment.
// func TestClusterSecretRequired(t *testing.T) {
// cl1Secret, err := pnet.GenerateV1Bytes()
// if err != nil {
// t.Fatal("Unable to generate cluster secret.")
// }
// cl1, _ := createOnePeerCluster(t, 1, (*cl1Secret)[:])
// cl2, _ := createOnePeerCluster(t, 2, testingClusterSecret)
// defer cleanRaft()
// defer cl1.Shutdown()
// defer cl2.Shutdown()
// peers1 := cl1.Peers()
// peers2 := cl2.Peers()
//
// _, err = cl1.PeerAdd(clusterAddr(cl2))
// if err == nil {
// t.Fatal("Peer entered private cluster without key.")
// }
// if len(peers1) != len(peers2) {
// t.Fatal("Expected same number of peers")
// }
// if len(peers1) != 1 {
// t.Fatal("Expected no peers other than self")
// }
// }