ipfs-cluster/config_test.go
Hector Sanjuan 34fdc329fc Fix #24: Auto-join and auto-leave operations for Cluster
This is the third implementation attempt. This time, rather than
broadcasting PeerAdd/Join requests to the whole cluster, we use the
consensus log to broadcast new peers joining.

This makes it easier to recover from errors and to know who exactly
is member of a cluster and who is not. The consensus is, after all,
meant to agree on things, and the list of cluster peers is something
everyone has to agree on.

Raft itself uses a special log operation to maintain the peer set.

The tests are almost unchanged from the previous attempts so it should
be the same, except it doesn't seem possible to bootstrap a bunch of nodes
at the same time using different bootstrap nodes. It works when using
the same. I'm not sure this worked before either, but the code is
simpler than recursively contacting peers, and scales better for
larger clusters.

Nodes have to be careful about joining clusters while keeping the state
from a different cluster (disjoint logs). This may cause problems with
Raft.

License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
2017-02-07 18:46:09 +01:00

95 lines
3.5 KiB
Go

package ipfscluster
import "testing"
func testingConfig() *Config {
jcfg := &JSONConfig{
ID: "QmUfSFm12eYCaRdypg48m8RqkXfLW7A2ZeGZb2skeHHDGA",
PrivateKey: "CAASqAkwggSkAgEAAoIBAQDpT16IRF6bb9tHsCbQ7M+nb2aI8sz8xyt8PoAWM42ki+SNoESIxKb4UhFxixKvtEdGxNE6aUUVc8kFk6wTStJ/X3IGiMetwkXiFiUxabUF/8A6SyvnSVDm+wFuavugpVrZikjLcfrf2xOVgnG3deQQvd/qbAv14jTwMFl+T+8d/cXBo8Mn/leLZCQun/EJEnkXP5MjgNI8XcWUE4NnH3E0ESSm6Pkm8MhMDZ2fmzNgqEyJ0GVinNgSml3Pyha3PBSj5LRczLip/ie4QkKx5OHvX2L3sNv/JIUHse5HSbjZ1c/4oGCYMVTYCykWiczrxBUOlcr8RwnZLOm4n2bCt5ZhAgMBAAECggEAVkePwfzmr7zR7tTpxeGNeXHtDUAdJm3RWwUSASPXgb5qKyXVsm5nAPX4lXDE3E1i/nzSkzNS5PgIoxNVU10cMxZs6JW0okFx7oYaAwgAddN6lxQtjD7EuGaixN6zZ1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pwHujYJGw4",
ClusterListenMultiaddress: "/ip4/127.0.0.1/tcp/10000",
APIListenMultiaddress: "/ip4/127.0.0.1/tcp/10002",
IPFSProxyListenMultiaddress: "/ip4/127.0.0.1/tcp/10001",
ConsensusDataFolder: "./raftFolderFromTests",
LeaveOnShutdown: true,
}
cfg, _ := jcfg.ToConfig()
return cfg
}
func TestDefaultConfig(t *testing.T) {
_, err := NewDefaultConfig()
if err != nil {
t.Fatal(err)
}
}
func TestConfigToJSON(t *testing.T) {
cfg, err := NewDefaultConfig()
if err != nil {
t.Fatal(err)
}
_, err = cfg.ToJSONConfig()
if err != nil {
t.Error(err)
}
}
func TestConfigToConfig(t *testing.T) {
cfg, _ := NewDefaultConfig()
j, _ := cfg.ToJSONConfig()
_, err := j.ToConfig()
if err != nil {
t.Error(err)
}
j.ID = "abc"
_, err = j.ToConfig()
if err == nil {
t.Error("expected error decoding ID")
}
j, _ = cfg.ToJSONConfig()
j.PrivateKey = "abc"
_, err = j.ToConfig()
if err == nil {
t.Error("expected error parsing private key")
}
j, _ = cfg.ToJSONConfig()
j.ClusterListenMultiaddress = "abc"
_, err = j.ToConfig()
if err == nil {
t.Error("expected error parsing cluster_listen_multiaddress")
}
j, _ = cfg.ToJSONConfig()
j.APIListenMultiaddress = "abc"
_, err = j.ToConfig()
if err == nil {
t.Error("expected error parsing api_listen_multiaddress")
}
j, _ = cfg.ToJSONConfig()
j.IPFSProxyListenMultiaddress = "abc"
_, err = j.ToConfig()
if err == nil {
t.Error("expected error parsing ipfs_proxy_listen_multiaddress")
}
j, _ = cfg.ToJSONConfig()
j.IPFSNodeMultiaddress = "abc"
_, err = j.ToConfig()
if err == nil {
t.Error("expected error parsing ipfs_node_multiaddress")
}
j, _ = cfg.ToJSONConfig()
j.Bootstrap = []string{"abc"}
_, err = j.ToConfig()
if err == nil {
t.Error("expected error parsing Bootstrap")
}
}