Skip to content
Snippets Groups Projects
Commit d29f8ecc authored by Jake Taylor's avatar Jake Taylor
Browse files

fix tests

parent d25ee4ac
No related branches found
No related tags found
3 merge requests!231Revert "Update store to print changes to the partners list",!187Xx 3829/triggers,!183manually connect new hosts added to the hostpool
......@@ -24,7 +24,7 @@ import (
// Tests that Backup.initializeBackup returns a new Backup with a copy of the
// key and the callback.
func Test_initializeBackup(t *testing.T) {
cbChan := make(chan []byte)
cbChan := make(chan []byte, 2)
cb := func(encryptedBackup []byte) { cbChan <- encryptedBackup }
expectedPassword := "MySuperSecurePassword"
b, err := initializeBackup(expectedPassword, cb, nil,
......@@ -34,6 +34,12 @@ func Test_initializeBackup(t *testing.T) {
t.Errorf("initializeBackup returned an error: %+v", err)
}
select {
case <-cbChan:
case <-time.After(10 * time.Millisecond):
t.Error("Timed out waiting for callback.")
}
// Check that the correct password is in storage
loadedPassword, err := loadPassword(b.store.GetKV())
if err != nil {
......@@ -89,6 +95,12 @@ func Test_resumeBackup(t *testing.T) {
t.Errorf("Failed to initialize new Backup: %+v", err)
}
select {
case <-cbChan1:
case <-time.After(10 * time.Millisecond):
t.Error("Timed out waiting for callback.")
}
// Get key and salt to compare to later
key1, salt1, _, err := loadBackup(b.store.GetKV())
if err != nil {
......@@ -135,7 +147,7 @@ func Test_resumeBackup(t *testing.T) {
select {
case r := <-cbChan1:
t.Errorf("Callback of first Backup called: %q", r) // TODO: i think there is a race condition here
t.Errorf("Callback of first Backup called: %q", r)
case r := <-cbChan2:
if !bytes.Equal(encryptedBackup, r) {
t.Errorf("Callback has unexepected data."+
......
......@@ -78,7 +78,7 @@ type PoolParams struct {
PoolSize uint32 // Allows override of HostPool size. Set to zero for dynamic size calculation
ProxyAttempts uint32 // How many proxies will be used in event of send failure
MaxPings uint32 // How many gateways to concurrently test when initializing HostPool. Disabled if zero.
LazyConnection bool // Flag determining whether Host connections are initialized when added to HostPool
ForceConnection bool // Flag determining whether Host connections are initialized when added to HostPool
HostParams connect.HostParams // Parameters for the creation of new Host objects
}
......@@ -89,7 +89,7 @@ func DefaultPoolParams() PoolParams {
ProxyAttempts: 5,
PoolSize: 0,
MaxPings: 0,
LazyConnection: true,
ForceConnection: false,
HostParams: connect.GetDefaultHostParams(),
}
p.HostParams.MaxRetries = 1
......@@ -550,7 +550,7 @@ func (h *HostPool) replaceHostNoStore(newId *id.ID, oldPoolIndex uint32) error {
}
// Manually connect the new Host
if !h.poolParams.LazyConnection {
if h.poolParams.ForceConnection {
go func() {
err := newHost.Connect()
if err != nil {
......@@ -664,7 +664,6 @@ func (h *HostPool) addGateway(gwId *id.ID, ndfIndex int) {
// Check if the host exists
host, ok := h.manager.GetHost(gwId)
if !ok {
// Check if gateway ID collides with an existing hard coded ID
if id.CollidesWithHardCodedID(gwId) {
jww.ERROR.Printf("Gateway ID invalid, collides with a "+
......
......@@ -490,6 +490,7 @@ func TestHostPool_UpdateNdf(t *testing.T) {
hostMap: make(map[id.ID]uint32),
ndf: testNdf,
storage: storage.InitTestingSession(t),
poolParams: DefaultPoolParams(),
filter: func(m map[id.ID]int, _ *ndf.NetworkDefinition) map[id.ID]int {
return m
},
......@@ -855,6 +856,7 @@ func TestHostPool_AddGateway(t *testing.T) {
hostList: make([]*connect.Host, newIndex+1),
hostMap: make(map[id.ID]uint32),
ndf: testNdf,
poolParams: params,
addGatewayChan: make(chan network.NodeGateway),
storage: storage.InitTestingSession(t),
}
......@@ -888,6 +890,7 @@ func TestHostPool_RemoveGateway(t *testing.T) {
hostList: make([]*connect.Host, newIndex+1),
hostMap: make(map[id.ID]uint32),
ndf: testNdf,
poolParams: params,
addGatewayChan: make(chan network.NodeGateway),
storage: storage.InitTestingSession(t),
rng: fastRNG.NewStreamGenerator(1, 1, csprng.NewSystemRNG),
......
......@@ -133,6 +133,7 @@ func NewManager(session *storage.Session, switchboard *switchboard.Switchboard,
poolParams.HostParams.KaClientOpts.Time = time.Duration(math.MaxInt64)
// Enable optimized HostPool initialization
poolParams.MaxPings = 50
poolParams.ForceConnection = true
m.sender, err = gateway.NewSender(poolParams, rng,
ndf, comms, session, m.NodeRegistration)
if err != nil {
......
......@@ -17,10 +17,10 @@ func (mc *MockSendCMIXComms) GetHost(*id.ID) (*connect.Host, bool) {
nid1 := id.NewIdFromString("zezima", id.Node, mc.t)
gwID := nid1.DeepCopy()
gwID.SetType(id.Gateway)
h, _ := connect.NewHost(gwID, "0.0.0.0", []byte(""), connect.HostParams{
MaxRetries: 0,
AuthEnabled: false,
})
p := connect.GetDefaultHostParams()
p.MaxRetries = 0
p.AuthEnabled = false
h, _ := connect.NewHost(gwID, "0.0.0.0", []byte(""), p)
return h, true
}
......
......@@ -20,7 +20,7 @@ import (
)
func TestMain(m *testing.M) {
jww.SetStdoutThreshold(jww.LevelTrace)
jww.SetStdoutThreshold(jww.LevelDebug)
connect.TestingOnlyDisableTLS = true
os.Exit(m.Run())
}
......
......@@ -62,10 +62,10 @@ func (mmrc *mockMessageRetrievalComms) RemoveHost(hid *id.ID) {
}
func (mmrc *mockMessageRetrievalComms) GetHost(hostId *id.ID) (*connect.Host, bool) {
h, _ := connect.NewHost(hostId, "0.0.0.0", []byte(""), connect.HostParams{
MaxRetries: 0,
AuthEnabled: false,
})
p := connect.GetDefaultHostParams()
p.MaxRetries = 0
p.AuthEnabled = false
h, _ := connect.NewHost(hostId, "0.0.0.0", []byte(""), p)
return h, true
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment