vfs: test poll interval update lifecycle
This commit is contained in:
committed by
Nick Craig-Wood
parent
f132aef295
commit
d5275c4ebb
+81
-17
@@ -90,6 +90,26 @@ func TestRcRefresh(t *testing.T) {
|
||||
// FIXME needs more tests
|
||||
}
|
||||
|
||||
func newTestPollVFS(t *testing.T, changeNotify func(context.Context, func(string, fs.EntryType), <-chan time.Duration)) (*fstest.Run, *VFS, *rc.Call) {
|
||||
t.Helper()
|
||||
r := fstest.NewRun(t)
|
||||
features := r.Fremote.Features()
|
||||
originalChangeNotify := features.ChangeNotify
|
||||
features.ChangeNotify = changeNotify
|
||||
t.Cleanup(func() {
|
||||
features.ChangeNotify = originalChangeNotify
|
||||
})
|
||||
vfs := New(context.Background(), r.Fremote, nil)
|
||||
t.Cleanup(func() {
|
||||
if vfs.inUse.Load() > 0 {
|
||||
vfs.Shutdown()
|
||||
}
|
||||
})
|
||||
call := rc.Calls.Get("vfs/poll-interval")
|
||||
require.NotNil(t, call)
|
||||
return r, vfs, call
|
||||
}
|
||||
|
||||
func TestRcPollInterval(t *testing.T) {
|
||||
r, vfs, call := rcNewRun(t, "vfs/poll-interval")
|
||||
_ = vfs
|
||||
@@ -103,31 +123,15 @@ func TestRcPollInterval(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRcPollIntervalShutdown(t *testing.T) {
|
||||
r := fstest.NewRun(t)
|
||||
features := r.Fremote.Features()
|
||||
originalChangeNotify := features.ChangeNotify
|
||||
t.Cleanup(func() {
|
||||
features.ChangeNotify = originalChangeNotify
|
||||
})
|
||||
|
||||
initialIntervalReceived := make(chan struct{})
|
||||
features.ChangeNotify = func(_ context.Context, _ func(string, fs.EntryType), pollInterval <-chan time.Duration) {
|
||||
r, vfs, call := newTestPollVFS(t, func(_ context.Context, _ func(string, fs.EntryType), pollInterval <-chan time.Duration) {
|
||||
go func() {
|
||||
<-pollInterval
|
||||
close(initialIntervalReceived)
|
||||
}()
|
||||
}
|
||||
|
||||
vfs := New(context.Background(), r.Fremote, nil)
|
||||
t.Cleanup(func() {
|
||||
if vfs.inUse.Load() > 0 {
|
||||
vfs.Shutdown()
|
||||
}
|
||||
})
|
||||
<-initialIntervalReceived
|
||||
|
||||
call := rc.Calls.Get("vfs/poll-interval")
|
||||
require.NotNil(t, call)
|
||||
originalInterval := vfs.Opt.PollInterval
|
||||
|
||||
type result struct {
|
||||
@@ -171,6 +175,66 @@ func TestRcPollIntervalShutdown(t *testing.T) {
|
||||
assert.Equal(t, originalInterval, vfs.Opt.PollInterval)
|
||||
}
|
||||
|
||||
func TestRcPollIntervalUpdate(t *testing.T) {
|
||||
intervals := make(chan time.Duration, 2)
|
||||
r, vfs, call := newTestPollVFS(t, func(_ context.Context, _ func(string, fs.EntryType), pollInterval <-chan time.Duration) {
|
||||
go func() {
|
||||
for interval := range pollInterval {
|
||||
intervals <- interval
|
||||
}
|
||||
}()
|
||||
})
|
||||
|
||||
assert.Equal(t, time.Duration(vfs.Opt.PollInterval), <-intervals)
|
||||
status, err := call.Fn(context.Background(), rc.Params{
|
||||
"fs": fs.ConfigString(r.Fremote),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, true, status["supported"])
|
||||
assert.Equal(t, vfs.Opt.PollInterval != 0, status["enabled"])
|
||||
|
||||
out, err := call.Fn(context.Background(), rc.Params{
|
||||
"fs": fs.ConfigString(r.Fremote),
|
||||
"interval": "1h",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, time.Hour, <-intervals)
|
||||
assert.Equal(t, fs.Duration(time.Hour), vfs.Opt.PollInterval)
|
||||
assert.Equal(t, false, out["timeout"])
|
||||
}
|
||||
|
||||
func TestRcPollIntervalTimeout(t *testing.T) {
|
||||
initialIntervalReceived := make(chan struct{})
|
||||
r, vfs, call := newTestPollVFS(t, func(_ context.Context, _ func(string, fs.EntryType), pollInterval <-chan time.Duration) {
|
||||
go func() {
|
||||
<-pollInterval
|
||||
close(initialIntervalReceived)
|
||||
}()
|
||||
})
|
||||
<-initialIntervalReceived
|
||||
originalInterval := vfs.Opt.PollInterval
|
||||
|
||||
out, err := call.Fn(context.Background(), rc.Params{
|
||||
"fs": fs.ConfigString(r.Fremote),
|
||||
"interval": "1h",
|
||||
"timeout": "10ms",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, true, out["timeout"])
|
||||
assert.Equal(t, originalInterval, vfs.Opt.PollInterval)
|
||||
}
|
||||
|
||||
func TestRcPollIntervalUnsupported(t *testing.T) {
|
||||
r, vfs, call := newTestPollVFS(t, nil)
|
||||
out, err := call.Fn(context.Background(), rc.Params{
|
||||
"fs": fs.ConfigString(r.Fremote),
|
||||
"interval": "1h",
|
||||
})
|
||||
require.EqualError(t, err, "poll-interval is not supported by this remote")
|
||||
assert.Nil(t, out)
|
||||
assert.Nil(t, vfs.pollChan)
|
||||
}
|
||||
|
||||
func TestRcList(t *testing.T) {
|
||||
r, vfs, call := rcNewRun(t, "vfs/list")
|
||||
_ = vfs
|
||||
|
||||
Reference in New Issue
Block a user