Official cwtch.im peer and server implementations. https://cwtch.im
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

74 lines
1.9 KiB

  1. // Known race issue with event bus channel closure
  2. package storage
  3. import (
  4. "cwtch.im/cwtch/event"
  5. "cwtch.im/cwtch/storage/v0"
  6. "fmt"
  7. "git.openprivacy.ca/openprivacy/log"
  8. "os"
  9. "testing"
  10. "time"
  11. )
  12. const testingDir = "./testing"
  13. const filenameBase = "testStream"
  14. const password = "asdfqwer"
  15. const line1 = "Hello from storage!"
  16. const testProfileName = "Alice"
  17. const testKey = "key"
  18. const testVal = "value"
  19. const testInitialMessage = "howdy"
  20. const testMessage = "Hello from storage"
  21. func TestProfileStoreUpgradeV0toV1(t *testing.T) {
  22. log.SetLevel(log.LevelDebug)
  23. os.RemoveAll(testingDir)
  24. eventBus := event.NewEventManager()
  25. queue := event.NewQueue()
  26. eventBus.Subscribe(event.ChangePasswordSuccess, queue)
  27. fmt.Println("Creating and initializing v0 profile and store...")
  28. profile := NewProfile(testProfileName)
  29. ps1 := v0.NewProfileWriterStore(eventBus, testingDir, password, profile)
  30. groupid, invite, err := profile.StartGroup("2c3kmoobnyghj2zw6pwv7d57yzld753auo3ugauezzpvfak3ahc4bdyd")
  31. if err != nil {
  32. t.Errorf("Creating group: %v\n", err)
  33. }
  34. if err != nil {
  35. t.Errorf("Creating group invite: %v\n", err)
  36. }
  37. ps1.AddGroup(invite, profile.Onion)
  38. fmt.Println("Sending 200 messages...")
  39. for i := 0; i < 200; i++ {
  40. ps1.AddGroupMessage(groupid, time.Now().Format(time.RFC3339Nano), time.Now().Format(time.RFC3339Nano), profile.Onion, testMessage)
  41. }
  42. fmt.Println("Shutdown v0 profile store...")
  43. ps1.Shutdown()
  44. fmt.Println("New v1 Profile store...")
  45. ps2, err := LoadProfileWriterStore(eventBus, testingDir, password)
  46. if err != nil {
  47. t.Errorf("Error createing new profileStore with new password: %v\n", err)
  48. return
  49. }
  50. profile2 := ps2.GetProfileCopy(true)
  51. if profile2.Groups[groupid] == nil {
  52. t.Errorf("Failed to load group %v\n", groupid)
  53. return
  54. }
  55. if len(profile2.Groups[groupid].Timeline.Messages) != 200 {
  56. t.Errorf("Failed to load group's 200 messages, instead got %v\n", len(profile2.Groups[groupid].Timeline.Messages))
  57. }
  58. }