From ed32a759ed8b596ddfc461b58f5b7fab2213b2a3 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sun, 21 Jun 2020 11:58:56 +0100 Subject: [PATCH] vfs: add test for writeBack.cancelUpload --- vfs/vfscache/writeback_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/vfs/vfscache/writeback_test.go b/vfs/vfscache/writeback_test.go index 6b7fd6f47..2e22d7d61 100644 --- a/vfs/vfscache/writeback_test.go +++ b/vfs/vfscache/writeback_test.go @@ -573,3 +573,35 @@ func TestWriteBackRemove(t *testing.T) { checkNotInLookup(t, wb, wbItem) assert.True(t, pi2.cancelled) } + +func TestWriteBackCancelUpload(t *testing.T) { + wb, cancel := newTestWriteBack(t) + defer cancel() + + item := &Item{} + + // cancel when not in writeback + assert.False(t, wb.cancelUpload(item)) + + // add item + pi := newPutItem(t) + wbItem := wb.add(item, "one", true, pi.put) + checkOnHeap(t, wb, wbItem) + checkInLookup(t, wb, wbItem) + + // cancel when not uploading + assert.False(t, wb.cancelUpload(item)) + checkOnHeap(t, wb, wbItem) + checkInLookup(t, wb, wbItem) + + // wait for upload to start + <-pi.started + checkNotOnHeap(t, wb, wbItem) + checkInLookup(t, wb, wbItem) + + // cancel when uploading + assert.True(t, wb.cancelUpload(item)) + checkOnHeap(t, wb, wbItem) + checkInLookup(t, wb, wbItem) + assert.True(t, pi.cancelled) +}