MCPcopy
hub / github.com/syncthing/syncthing / TestSyncSparseFile

Function TestSyncSparseFile

test/sync_test.go:313–380  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

311}
312
313func TestSyncSparseFile(t *testing.T) {
314 // This test verifies that when syncing a file that consists mostly of
315 // zeroes, those blocks are not transferred. It doesn't verify whether
316 // the resulting file is actually *sparse* or not.
317
318 log.Println("Cleaning...")
319 err := removeAll("s1", "s12-1",
320 "s2", "s12-2", "s23-2",
321 "s3", "s23-3",
322 "h1/index*", "h2/index*", "h3/index*")
323 if err != nil {
324 t.Fatal(err)
325 }
326
327 log.Println("Generating files...")
328
329 if err := os.Mkdir("s1", 0o755); err != nil {
330 t.Fatal(err)
331 }
332
333 fd, err := os.Create("s1/testfile")
334 if err != nil {
335 t.Fatal(err)
336 }
337 if _, err := fd.Write([]byte("Start")); err != nil {
338 t.Fatal(err)
339 }
340 kib := make([]byte, 1024)
341 for i := 0; i < 8192; i++ {
342 if _, err := fd.Write(kib); err != nil {
343 t.Fatal(err)
344 }
345 }
346 if _, err := fd.Write([]byte("End")); err != nil {
347 t.Fatal(err)
348 }
349 fd.Close()
350
351 // Start the syncers
352
353 log.Println("Syncing...")
354
355 p0 := startInstance(t, 1)
356 defer checkedStop(t, p0)
357 p1 := startInstance(t, 2)
358 defer checkedStop(t, p1)
359
360 p0.ResumeAll()
361 p1.ResumeAll()
362
363 rc.AwaitSync("default", p0, p1)
364
365 log.Println("Comparing...")
366
367 if err := compareDirectories("s1", "s2"); err != nil {
368 t.Fatal(err)
369 }
370

Callers

nothing calls this directly

Calls 12

AwaitSyncFunction · 0.92
removeAllFunction · 0.85
startInstanceFunction · 0.85
checkedStopFunction · 0.85
FatalMethod · 0.80
ResumeAllMethod · 0.80
ConnectionsMethod · 0.80
compareDirectoriesFunction · 0.70
MkdirMethod · 0.65
CreateMethod · 0.65
CloseMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected