MCPcopy
hub / github.com/syncthing/syncthing / TestDeregisterOnFailInCopy

Function TestDeregisterOnFailInCopy

lib/model/folder_sendrecv_test.go:345–441  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

343}
344
345func TestDeregisterOnFailInCopy(t *testing.T) {
346 file := setupFile("filex", []int{0, 2, 0, 0, 5, 0, 0, 8})
347
348 m, f := setupSendReceiveFolder(t)
349
350 // Set up our evet subscription early
351 s := m.evLogger.Subscribe(events.ItemFinished)
352
353 // queue.Done should be called by the finisher routine
354 f.queue.Push("filex", 0, time.Time{})
355 f.queue.Pop()
356
357 if f.queue.lenProgress() != 1 {
358 t.Fatal("Expected file in progress")
359 }
360
361 pullChan := make(chan pullBlockState)
362 finisherBufferChan := make(chan *sharedPullerState, 1)
363 finisherChan := make(chan *sharedPullerState)
364 dbUpdateChan := make(chan dbUpdateJob, 1)
365
366 copyChan, copyWg := startCopier(t.Context(), f, pullChan, finisherBufferChan)
367 go f.finisherRoutine(t.Context(), finisherChan, dbUpdateChan, make(chan string))
368
369 defer func() {
370 close(copyChan)
371 copyWg.Wait()
372 close(pullChan)
373 close(finisherBufferChan)
374 close(finisherChan)
375 }()
376
377 f.handleFile(t.Context(), file, copyChan)
378
379 // Receive a block at puller, to indicate that at least a single copier
380 // loop has been performed.
381 var toPull pullBlockState
382 select {
383 case toPull = <-pullChan:
384 case <-time.After(10 * time.Second):
385 t.Fatal("timed out")
386 }
387
388 // Unblock copier
389 go func() {
390 for range pullChan {
391 }
392 }()
393
394 // Close the file, causing errors on further access
395 toPull.sharedPullerState.fail(os.ErrNotExist)
396
397 select {
398 case state := <-finisherBufferChan:
399 // At this point the file should still be registered with both the job
400 // queue, and the progress emitter. Verify this.
401 if f.model.progressEmitter.lenRegistry() != 1 || f.queue.lenProgress() != 1 || f.queue.lenQueued() != 0 {
402 t.Fatal("Could not find file")

Callers

nothing calls this directly

Calls 15

setupFileFunction · 0.85
setupSendReceiveFolderFunction · 0.85
startCopierFunction · 0.85
lenProgressMethod · 0.80
FatalMethod · 0.80
finisherRoutineMethod · 0.80
handleFileMethod · 0.80
failMethod · 0.80
lenRegistryMethod · 0.80
lenQueuedMethod · 0.80
UnlockMethod · 0.80
SubscribeMethod · 0.65

Tested by

no test coverage detected