|
@@ -114,6 +114,9 @@ func TestSendDownloadProgressMessages(t *testing.T) {
|
|
|
|
|
|
p := NewProgressEmitter(c)
|
|
p := NewProgressEmitter(c)
|
|
p.temporaryIndexSubscribe(fc, []string{"folder", "folder2"})
|
|
p.temporaryIndexSubscribe(fc, []string{"folder", "folder2"})
|
|
|
|
+ p.registry["folder"] = make(map[string]*sharedPullerState)
|
|
|
|
+ p.registry["folder2"] = make(map[string]*sharedPullerState)
|
|
|
|
+ p.registry["folderXXX"] = make(map[string]*sharedPullerState)
|
|
|
|
|
|
expect := func(updateIdx int, state *sharedPullerState, updateType protocol.FileDownloadProgressUpdateType, version protocol.Vector, blocks []int32, remove bool) {
|
|
expect := func(updateIdx int, state *sharedPullerState, updateType protocol.FileDownloadProgressUpdateType, version protocol.Vector, blocks []int32, remove bool) {
|
|
messageIdx := -1
|
|
messageIdx := -1
|
|
@@ -202,39 +205,39 @@ func TestSendDownloadProgressMessages(t *testing.T) {
|
|
mut: sync.NewRWMutex(),
|
|
mut: sync.NewRWMutex(),
|
|
availableUpdated: time.Now(),
|
|
availableUpdated: time.Now(),
|
|
}
|
|
}
|
|
- p.registry["1"] = state1
|
|
|
|
|
|
+ p.registry["folder"]["1"] = state1
|
|
|
|
|
|
// Has no blocks, hence no message is sent
|
|
// Has no blocks, hence no message is sent
|
|
- p.sendDownloadProgressMessages()
|
|
|
|
|
|
+ sendMsgs(p)
|
|
expectEmpty()
|
|
expectEmpty()
|
|
|
|
|
|
// Returns update for puller with new extra blocks
|
|
// Returns update for puller with new extra blocks
|
|
state1.available = []int32{1}
|
|
state1.available = []int32{1}
|
|
- p.sendDownloadProgressMessages()
|
|
|
|
|
|
+ sendMsgs(p)
|
|
|
|
|
|
expect(0, state1, protocol.UpdateTypeAppend, v1, []int32{1}, true)
|
|
expect(0, state1, protocol.UpdateTypeAppend, v1, []int32{1}, true)
|
|
expectEmpty()
|
|
expectEmpty()
|
|
|
|
|
|
// Does nothing if nothing changes
|
|
// Does nothing if nothing changes
|
|
- p.sendDownloadProgressMessages()
|
|
|
|
|
|
+ sendMsgs(p)
|
|
expectEmpty()
|
|
expectEmpty()
|
|
|
|
|
|
// Does nothing if timestamp updated, but no new blocks (should never happen)
|
|
// Does nothing if timestamp updated, but no new blocks (should never happen)
|
|
state1.availableUpdated = tick()
|
|
state1.availableUpdated = tick()
|
|
|
|
|
|
- p.sendDownloadProgressMessages()
|
|
|
|
|
|
+ sendMsgs(p)
|
|
expectEmpty()
|
|
expectEmpty()
|
|
|
|
|
|
// Does not return an update if date blocks change but date does not (should never happen)
|
|
// Does not return an update if date blocks change but date does not (should never happen)
|
|
state1.available = []int32{1, 2}
|
|
state1.available = []int32{1, 2}
|
|
|
|
|
|
- p.sendDownloadProgressMessages()
|
|
|
|
|
|
+ sendMsgs(p)
|
|
expectEmpty()
|
|
expectEmpty()
|
|
|
|
|
|
// If the date and blocks changes, returns only the diff
|
|
// If the date and blocks changes, returns only the diff
|
|
state1.availableUpdated = tick()
|
|
state1.availableUpdated = tick()
|
|
|
|
|
|
- p.sendDownloadProgressMessages()
|
|
|
|
|
|
+ sendMsgs(p)
|
|
|
|
|
|
expect(0, state1, protocol.UpdateTypeAppend, v1, []int32{2}, true)
|
|
expect(0, state1, protocol.UpdateTypeAppend, v1, []int32{2}, true)
|
|
expectEmpty()
|
|
expectEmpty()
|
|
@@ -242,7 +245,7 @@ func TestSendDownloadProgressMessages(t *testing.T) {
|
|
// Returns forget and update if puller version has changed
|
|
// Returns forget and update if puller version has changed
|
|
state1.file.Version = v2
|
|
state1.file.Version = v2
|
|
|
|
|
|
- p.sendDownloadProgressMessages()
|
|
|
|
|
|
+ sendMsgs(p)
|
|
|
|
|
|
expect(0, state1, protocol.UpdateTypeForget, v1, nil, false)
|
|
expect(0, state1, protocol.UpdateTypeForget, v1, nil, false)
|
|
expect(1, state1, protocol.UpdateTypeAppend, v2, []int32{1, 2}, true)
|
|
expect(1, state1, protocol.UpdateTypeAppend, v2, []int32{1, 2}, true)
|
|
@@ -254,7 +257,7 @@ func TestSendDownloadProgressMessages(t *testing.T) {
|
|
state1.availableUpdated = tick()
|
|
state1.availableUpdated = tick()
|
|
state1.created = tick()
|
|
state1.created = tick()
|
|
|
|
|
|
- p.sendDownloadProgressMessages()
|
|
|
|
|
|
+ sendMsgs(p)
|
|
|
|
|
|
expect(0, state1, protocol.UpdateTypeForget, v2, nil, false)
|
|
expect(0, state1, protocol.UpdateTypeForget, v2, nil, false)
|
|
expect(1, state1, protocol.UpdateTypeAppend, v2, []int32{1}, true)
|
|
expect(1, state1, protocol.UpdateTypeAppend, v2, []int32{1}, true)
|
|
@@ -265,7 +268,7 @@ func TestSendDownloadProgressMessages(t *testing.T) {
|
|
state1.available = nil
|
|
state1.available = nil
|
|
state1.availableUpdated = tick()
|
|
state1.availableUpdated = tick()
|
|
|
|
|
|
- p.sendDownloadProgressMessages()
|
|
|
|
|
|
+ sendMsgs(p)
|
|
|
|
|
|
expect(0, state1, protocol.UpdateTypeForget, v2, nil, false)
|
|
expect(0, state1, protocol.UpdateTypeForget, v2, nil, false)
|
|
expect(1, state1, protocol.UpdateTypeAppend, v1, nil, true)
|
|
expect(1, state1, protocol.UpdateTypeAppend, v1, nil, true)
|
|
@@ -308,11 +311,11 @@ func TestSendDownloadProgressMessages(t *testing.T) {
|
|
available: []int32{1, 2, 3},
|
|
available: []int32{1, 2, 3},
|
|
availableUpdated: time.Now(),
|
|
availableUpdated: time.Now(),
|
|
}
|
|
}
|
|
- p.registry["2"] = state2
|
|
|
|
- p.registry["3"] = state3
|
|
|
|
- p.registry["4"] = state4
|
|
|
|
|
|
+ p.registry["folder2"]["2"] = state2
|
|
|
|
+ p.registry["folder"]["3"] = state3
|
|
|
|
+ p.registry["folder2"]["4"] = state4
|
|
|
|
|
|
- p.sendDownloadProgressMessages()
|
|
|
|
|
|
+ sendMsgs(p)
|
|
|
|
|
|
expect(-1, state1, protocol.UpdateTypeAppend, v1, []int32{1, 2, 3}, false)
|
|
expect(-1, state1, protocol.UpdateTypeAppend, v1, []int32{1, 2, 3}, false)
|
|
expect(-1, state3, protocol.UpdateTypeAppend, v1, []int32{1, 2, 3}, true)
|
|
expect(-1, state3, protocol.UpdateTypeAppend, v1, []int32{1, 2, 3}, true)
|
|
@@ -326,10 +329,10 @@ func TestSendDownloadProgressMessages(t *testing.T) {
|
|
state2.available = []int32{1, 2, 3, 4, 5}
|
|
state2.available = []int32{1, 2, 3, 4, 5}
|
|
state2.availableUpdated = tick()
|
|
state2.availableUpdated = tick()
|
|
|
|
|
|
- delete(p.registry, "3")
|
|
|
|
- delete(p.registry, "4")
|
|
|
|
|
|
+ delete(p.registry["folder"], "3")
|
|
|
|
+ delete(p.registry["folder2"], "4")
|
|
|
|
|
|
- p.sendDownloadProgressMessages()
|
|
|
|
|
|
+ sendMsgs(p)
|
|
|
|
|
|
expect(-1, state1, protocol.UpdateTypeAppend, v1, []int32{4, 5}, false)
|
|
expect(-1, state1, protocol.UpdateTypeAppend, v1, []int32{4, 5}, false)
|
|
expect(-1, state3, protocol.UpdateTypeForget, v1, nil, true)
|
|
expect(-1, state3, protocol.UpdateTypeForget, v1, nil, true)
|
|
@@ -338,8 +341,8 @@ func TestSendDownloadProgressMessages(t *testing.T) {
|
|
expectEmpty()
|
|
expectEmpty()
|
|
|
|
|
|
// Deletions are sent only once (actual bug I found writing the tests)
|
|
// Deletions are sent only once (actual bug I found writing the tests)
|
|
- p.sendDownloadProgressMessages()
|
|
|
|
- p.sendDownloadProgressMessages()
|
|
|
|
|
|
+ sendMsgs(p)
|
|
|
|
+ sendMsgs(p)
|
|
expectEmpty()
|
|
expectEmpty()
|
|
|
|
|
|
// Not sent for "inactive" (symlinks, dirs, or wrong folder) pullers
|
|
// Not sent for "inactive" (symlinks, dirs, or wrong folder) pullers
|
|
@@ -392,31 +395,31 @@ func TestSendDownloadProgressMessages(t *testing.T) {
|
|
available: []int32{1, 2, 3},
|
|
available: []int32{1, 2, 3},
|
|
availableUpdated: time.Now(),
|
|
availableUpdated: time.Now(),
|
|
}
|
|
}
|
|
- p.registry["5"] = state5
|
|
|
|
- p.registry["6"] = state6
|
|
|
|
- p.registry["7"] = state7
|
|
|
|
- p.registry["8"] = state8
|
|
|
|
|
|
+ p.registry["folder"]["5"] = state5
|
|
|
|
+ p.registry["folder"]["6"] = state6
|
|
|
|
+ p.registry["folderXXX"]["7"] = state7
|
|
|
|
+ p.registry["folder"]["8"] = state8
|
|
|
|
|
|
- p.sendDownloadProgressMessages()
|
|
|
|
|
|
+ sendMsgs(p)
|
|
|
|
|
|
expectEmpty()
|
|
expectEmpty()
|
|
|
|
|
|
// Device is no longer subscribed to a particular folder
|
|
// Device is no longer subscribed to a particular folder
|
|
- delete(p.registry, "1") // Clean up first
|
|
|
|
- delete(p.registry, "2") // Clean up first
|
|
|
|
|
|
+ delete(p.registry["folder"], "1") // Clean up first
|
|
|
|
+ delete(p.registry["folder2"], "2") // Clean up first
|
|
|
|
|
|
- p.sendDownloadProgressMessages()
|
|
|
|
|
|
+ sendMsgs(p)
|
|
expect(-1, state1, protocol.UpdateTypeForget, v1, nil, true)
|
|
expect(-1, state1, protocol.UpdateTypeForget, v1, nil, true)
|
|
expect(-1, state2, protocol.UpdateTypeForget, v1, nil, true)
|
|
expect(-1, state2, protocol.UpdateTypeForget, v1, nil, true)
|
|
|
|
|
|
expectEmpty()
|
|
expectEmpty()
|
|
|
|
|
|
- p.registry["1"] = state1
|
|
|
|
- p.registry["2"] = state2
|
|
|
|
- p.registry["3"] = state3
|
|
|
|
- p.registry["4"] = state4
|
|
|
|
|
|
+ p.registry["folder"]["1"] = state1
|
|
|
|
+ p.registry["folder2"]["2"] = state2
|
|
|
|
+ p.registry["folder"]["3"] = state3
|
|
|
|
+ p.registry["folder2"]["4"] = state4
|
|
|
|
|
|
- p.sendDownloadProgressMessages()
|
|
|
|
|
|
+ sendMsgs(p)
|
|
|
|
|
|
expect(-1, state1, protocol.UpdateTypeAppend, v1, []int32{1, 2, 3, 4, 5}, false)
|
|
expect(-1, state1, protocol.UpdateTypeAppend, v1, []int32{1, 2, 3, 4, 5}, false)
|
|
expect(-1, state3, protocol.UpdateTypeAppend, v1, []int32{1, 2, 3}, true)
|
|
expect(-1, state3, protocol.UpdateTypeAppend, v1, []int32{1, 2, 3}, true)
|
|
@@ -427,7 +430,7 @@ func TestSendDownloadProgressMessages(t *testing.T) {
|
|
p.temporaryIndexUnsubscribe(fc)
|
|
p.temporaryIndexUnsubscribe(fc)
|
|
p.temporaryIndexSubscribe(fc, []string{"folder"})
|
|
p.temporaryIndexSubscribe(fc, []string{"folder"})
|
|
|
|
|
|
- p.sendDownloadProgressMessages()
|
|
|
|
|
|
+ sendMsgs(p)
|
|
|
|
|
|
// See progressemitter.go for explanation why this is commented out.
|
|
// See progressemitter.go for explanation why this is commented out.
|
|
// Search for state.cleanup
|
|
// Search for state.cleanup
|
|
@@ -439,9 +442,15 @@ func TestSendDownloadProgressMessages(t *testing.T) {
|
|
// Cleanup when device no longer exists
|
|
// Cleanup when device no longer exists
|
|
p.temporaryIndexUnsubscribe(fc)
|
|
p.temporaryIndexUnsubscribe(fc)
|
|
|
|
|
|
- p.sendDownloadProgressMessages()
|
|
|
|
|
|
+ sendMsgs(p)
|
|
_, ok := p.sentDownloadStates[fc.ID()]
|
|
_, ok := p.sentDownloadStates[fc.ID()]
|
|
if ok {
|
|
if ok {
|
|
t.Error("Should not be there")
|
|
t.Error("Should not be there")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func sendMsgs(p *ProgressEmitter) {
|
|
|
|
+ p.mut.Lock()
|
|
|
|
+ defer p.mut.Unlock()
|
|
|
|
+ p.sendDownloadProgressMessagesLocked()
|
|
|
|
+}
|