cmd/syncthing: Allow custom event subscriptions (fixes #1879)
This adds a parameter "events" to the /rest/events endpoint. It should be a comma separated list of the events the consumer is interested in. When not given it defaults to the current set of events, so it's backwards compatible. The API service then manages subscriptions, creating them as required for each requested event mask. Old subscriptions are not "garbage collected" - it's assumed that in normal usage the set of event subscriptions will be small enough. Possibly lower than before, as we will not set up the disk event subscription unless it's actually used. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4092
This commit is contained in:
committed by
Audrius Butkevicius
parent
75460be98d
commit
d48e46a29c
@@ -23,6 +23,7 @@ import (
|
||||
|
||||
"github.com/d4l3k/messagediff"
|
||||
"github.com/syncthing/syncthing/lib/config"
|
||||
"github.com/syncthing/syncthing/lib/events"
|
||||
"github.com/syncthing/syncthing/lib/protocol"
|
||||
"github.com/syncthing/syncthing/lib/sync"
|
||||
"github.com/thejerf/suture"
|
||||
@@ -924,3 +925,34 @@ func TestOptionsRequest(t *testing.T) {
|
||||
t.Fatal("OPTIONS on /rest/system/status should return a 'Access-Control-Allow-Headers: Content-Type, X-API-KEY' header")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEventMasks(t *testing.T) {
|
||||
cfg := new(mockedConfig)
|
||||
defSub := new(mockedEventSub)
|
||||
diskSub := new(mockedEventSub)
|
||||
svc := newAPIService(protocol.LocalDeviceID, cfg, "", "", "", nil, defSub, diskSub, nil, nil, nil, nil)
|
||||
|
||||
if mask := svc.getEventMask(""); mask != defaultEventMask {
|
||||
t.Errorf("incorrect default mask %x != %x", int64(mask), int64(defaultEventMask))
|
||||
}
|
||||
|
||||
expected := events.FolderSummary | events.LocalChangeDetected
|
||||
if mask := svc.getEventMask("FolderSummary,LocalChangeDetected"); mask != expected {
|
||||
t.Errorf("incorrect parsed mask %x != %x", int64(mask), int64(expected))
|
||||
}
|
||||
|
||||
expected = 0
|
||||
if mask := svc.getEventMask("WeirdEvent,something else that doens't exist"); mask != expected {
|
||||
t.Errorf("incorrect parsed mask %x != %x", int64(mask), int64(expected))
|
||||
}
|
||||
|
||||
if res := svc.getEventSub(defaultEventMask); res != defSub {
|
||||
t.Errorf("should have returned the given default event sub")
|
||||
}
|
||||
if res := svc.getEventSub(diskEventMask); res != diskSub {
|
||||
t.Errorf("should have returned the given disk event sub")
|
||||
}
|
||||
if res := svc.getEventSub(events.LocalIndexUpdated); res == nil || res == defSub || res == diskSub {
|
||||
t.Errorf("should have returned a valid, non-default event sub")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user