2019-11-08 00:39:27 +00:00
|
|
|
// Known race issue with event bus channel closure
|
|
|
|
|
2019-01-29 20:56:59 +00:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"cwtch.im/cwtch/event"
|
2020-01-13 22:11:00 +00:00
|
|
|
"cwtch.im/cwtch/storage/v0"
|
2019-12-12 20:21:14 +00:00
|
|
|
"fmt"
|
2020-02-10 22:09:24 +00:00
|
|
|
"git.openprivacy.ca/openprivacy/log"
|
2019-01-29 20:56:59 +00:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2020-01-13 22:11:00 +00:00
|
|
|
const testingDir = "./testing"
|
|
|
|
const filenameBase = "testStream"
|
|
|
|
const password = "asdfqwer"
|
|
|
|
const line1 = "Hello from storage!"
|
2019-01-29 20:56:59 +00:00
|
|
|
const testProfileName = "Alice"
|
|
|
|
const testKey = "key"
|
|
|
|
const testVal = "value"
|
|
|
|
const testInitialMessage = "howdy"
|
|
|
|
const testMessage = "Hello from storage"
|
|
|
|
|
2020-01-13 22:11:00 +00:00
|
|
|
func TestProfileStoreUpgradeV0toV1(t *testing.T) {
|
|
|
|
log.SetLevel(log.LevelDebug)
|
2019-12-12 20:21:14 +00:00
|
|
|
os.RemoveAll(testingDir)
|
|
|
|
eventBus := event.NewEventManager()
|
|
|
|
|
|
|
|
queue := event.NewQueue()
|
|
|
|
eventBus.Subscribe(event.ChangePasswordSuccess, queue)
|
|
|
|
|
2020-01-13 22:11:00 +00:00
|
|
|
fmt.Println("Creating and initializing v0 profile and store...")
|
2019-12-12 20:21:14 +00:00
|
|
|
profile := NewProfile(testProfileName)
|
2020-01-13 22:11:00 +00:00
|
|
|
ps1 := v0.NewProfileWriterStore(eventBus, testingDir, password, profile)
|
2019-12-12 20:21:14 +00:00
|
|
|
|
|
|
|
groupid, invite, err := profile.StartGroup("2c3kmoobnyghj2zw6pwv7d57yzld753auo3ugauezzpvfak3ahc4bdyd")
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Creating group: %v\n", err)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Creating group invite: %v\n", err)
|
|
|
|
}
|
|
|
|
|
2021-05-03 23:32:48 +00:00
|
|
|
ps1.AddGroup(invite)
|
2019-12-12 20:21:14 +00:00
|
|
|
|
|
|
|
fmt.Println("Sending 200 messages...")
|
|
|
|
|
|
|
|
for i := 0; i < 200; i++ {
|
2020-01-13 22:11:00 +00:00
|
|
|
ps1.AddGroupMessage(groupid, time.Now().Format(time.RFC3339Nano), time.Now().Format(time.RFC3339Nano), profile.Onion, testMessage)
|
2019-12-12 20:21:14 +00:00
|
|
|
}
|
|
|
|
|
2020-01-13 22:11:00 +00:00
|
|
|
fmt.Println("Shutdown v0 profile store...")
|
2019-12-12 20:21:14 +00:00
|
|
|
ps1.Shutdown()
|
|
|
|
|
2020-01-13 22:11:00 +00:00
|
|
|
fmt.Println("New v1 Profile store...")
|
|
|
|
ps2, err := LoadProfileWriterStore(eventBus, testingDir, password)
|
2019-12-12 20:21:14 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error createing new profileStore with new password: %v\n", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
profile2 := ps2.GetProfileCopy(true)
|
|
|
|
|
|
|
|
if profile2.Groups[groupid] == nil {
|
|
|
|
t.Errorf("Failed to load group %v\n", groupid)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-13 22:11:00 +00:00
|
|
|
if len(profile2.Groups[groupid].Timeline.Messages) != 200 {
|
|
|
|
t.Errorf("Failed to load group's 200 messages, instead got %v\n", len(profile2.Groups[groupid].Timeline.Messages))
|
2019-12-12 20:21:14 +00:00
|
|
|
}
|
|
|
|
}
|