Skip to content
Snippets Groups Projects
Commit bdfd2211 authored by Richard T. Carback III's avatar Richard T. Carback III
Browse files

Fix tests associated with backup triggering on initialization

parent d479cb88
Branches
Tags
2 merge requests!231Revert "Update store to print changes to the partners list",!171RestoreContactsFromBackup
......@@ -111,7 +111,7 @@ func initializeBackup(password string, updateBackupCb UpdateBackupFn,
// Setting backup trigger in client
b.backupContainer.SetBackup(b.TriggerBackup)
b.backupContainer.TriggerBackup("initializeBackup")
b.TriggerBackup("initializeBackup")
jww.INFO.Print("Initialized backup with new user key.")
return b, nil
......@@ -199,7 +199,13 @@ func (b *Backup) TriggerBackup(reason string) {
jww.INFO.Printf("Backup triggered: %s", reason)
// Send backup on callback
b.mux.RLock()
defer b.mux.RUnlock()
if b.updateBackupCb != nil {
go b.updateBackupCb(encryptedBackup)
} else {
jww.WARN.Printf("could not call backup callback, stopped...")
}
}
// StopBackup stops the backup processes and deletes the user's password, key,
......
......@@ -9,15 +9,16 @@ package backup
import (
"bytes"
"reflect"
"strings"
"testing"
"time"
"gitlab.com/elixxir/client/interfaces"
"gitlab.com/elixxir/client/storage"
"gitlab.com/elixxir/crypto/backup"
"gitlab.com/elixxir/crypto/fastRNG"
"gitlab.com/xx_network/crypto/csprng"
"reflect"
"strings"
"testing"
"time"
)
// Tests that Backup.initializeBackup returns a new Backup with a copy of the
......@@ -196,6 +197,11 @@ func TestBackup_TriggerBackup_NoKey(t *testing.T) {
cbChan := make(chan []byte)
cb := func(encryptedBackup []byte) { cbChan <- encryptedBackup }
b := newTestBackup("MySuperSecurePassword", cb, t)
select {
case <-cbChan:
case <-time.After(10 * time.Millisecond):
t.Errorf("backup not called")
}
err := deleteBackup(b.store.GetKV())
if err != nil {
......@@ -209,6 +215,7 @@ func TestBackup_TriggerBackup_NoKey(t *testing.T) {
t.Errorf("Callback received when it should not have been called: %q", r)
case <-time.After(10 * time.Millisecond):
}
}
// Tests that Backup.StopBackup prevents the callback from triggering and that
......@@ -217,6 +224,11 @@ func TestBackup_StopBackup(t *testing.T) {
cbChan := make(chan []byte)
cb := func(encryptedBackup []byte) { cbChan <- encryptedBackup }
b := newTestBackup("MySuperSecurePassword", cb, t)
select {
case <-cbChan:
case <-time.After(1000 * time.Millisecond):
t.Errorf("backup not called")
}
err := b.StopBackup()
if err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment