"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
vfs: test poll interval update lifecycle
Loi Nguyend5275c4ebb82
diff --git a/vfs/rc_test.go b/vfs/rc_test.goindex 4de99d57d..f6db7585a 100644--- a/vfs/rc_test.go+++ b/vfs/rc_test.go@@ -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() {<-pollIntervalclose(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.PollIntervaltype 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