1
0

rwfolder_test.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. // Copyright (C) 2014 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at http://mozilla.org/MPL/2.0/.
  6. package model
  7. import (
  8. "os"
  9. "path/filepath"
  10. "testing"
  11. "time"
  12. "github.com/syncthing/syncthing/lib/db"
  13. "github.com/syncthing/syncthing/lib/protocol"
  14. "github.com/syncthing/syncthing/lib/scanner"
  15. "github.com/syncthing/syncthing/lib/sync"
  16. )
  17. func init() {
  18. // We do this to make sure that the temp file required for the tests does
  19. // not get removed during the tests.
  20. future := time.Now().Add(time.Hour)
  21. err := os.Chtimes(filepath.Join("testdata", defTempNamer.TempName("file")), future, future)
  22. if err != nil {
  23. panic(err)
  24. }
  25. }
  26. var blocks = []protocol.BlockInfo{
  27. {Hash: []uint8{0xfa, 0x43, 0x23, 0x9b, 0xce, 0xe7, 0xb9, 0x7c, 0xa6, 0x2f, 0x0, 0x7c, 0xc6, 0x84, 0x87, 0x56, 0xa, 0x39, 0xe1, 0x9f, 0x74, 0xf3, 0xdd, 0xe7, 0x48, 0x6d, 0xb3, 0xf9, 0x8d, 0xf8, 0xe4, 0x71}}, // Zero'ed out block
  28. {Offset: 0, Size: 0x20000, Hash: []uint8{0x7e, 0xad, 0xbc, 0x36, 0xae, 0xbb, 0xcf, 0x74, 0x43, 0xe2, 0x7a, 0x5a, 0x4b, 0xb8, 0x5b, 0xce, 0xe6, 0x9e, 0x1e, 0x10, 0xf9, 0x8a, 0xbc, 0x77, 0x95, 0x2, 0x29, 0x60, 0x9e, 0x96, 0xae, 0x6c}},
  29. {Offset: 131072, Size: 0x20000, Hash: []uint8{0x3c, 0xc4, 0x20, 0xf4, 0xb, 0x2e, 0xcb, 0xb9, 0x5d, 0xce, 0x34, 0xa8, 0xc3, 0x92, 0xea, 0xf3, 0xda, 0x88, 0x33, 0xee, 0x7a, 0xb6, 0xe, 0xf1, 0x82, 0x5e, 0xb0, 0xa9, 0x26, 0xa9, 0xc0, 0xef}},
  30. {Offset: 262144, Size: 0x20000, Hash: []uint8{0x76, 0xa8, 0xc, 0x69, 0xd7, 0x5c, 0x52, 0xfd, 0xdf, 0x55, 0xef, 0x44, 0xc1, 0xd6, 0x25, 0x48, 0x4d, 0x98, 0x48, 0x4d, 0xaa, 0x50, 0xf6, 0x6b, 0x32, 0x47, 0x55, 0x81, 0x6b, 0xed, 0xee, 0xfb}},
  31. {Offset: 393216, Size: 0x20000, Hash: []uint8{0x44, 0x1e, 0xa4, 0xf2, 0x8d, 0x1f, 0xc3, 0x1b, 0x9d, 0xa5, 0x18, 0x5e, 0x59, 0x1b, 0xd8, 0x5c, 0xba, 0x7d, 0xb9, 0x8d, 0x70, 0x11, 0x5c, 0xea, 0xa1, 0x57, 0x4d, 0xcb, 0x3c, 0x5b, 0xf8, 0x6c}},
  32. {Offset: 524288, Size: 0x20000, Hash: []uint8{0x8, 0x40, 0xd0, 0x5e, 0x80, 0x0, 0x0, 0x7c, 0x8b, 0xb3, 0x8b, 0xf7, 0x7b, 0x23, 0x26, 0x28, 0xab, 0xda, 0xcf, 0x86, 0x8f, 0xc2, 0x8a, 0x39, 0xc6, 0xe6, 0x69, 0x59, 0x97, 0xb6, 0x1a, 0x43}},
  33. {Offset: 655360, Size: 0x20000, Hash: []uint8{0x38, 0x8e, 0x44, 0xcb, 0x30, 0xd8, 0x90, 0xf, 0xce, 0x7, 0x4b, 0x58, 0x86, 0xde, 0xce, 0x59, 0xa2, 0x46, 0xd2, 0xf9, 0xba, 0xaf, 0x35, 0x87, 0x38, 0xdf, 0xd2, 0xd, 0xf9, 0x45, 0xed, 0x91}},
  34. {Offset: 786432, Size: 0x20000, Hash: []uint8{0x32, 0x28, 0xcd, 0xf, 0x37, 0x21, 0xe5, 0xd4, 0x1e, 0x58, 0x87, 0x73, 0x8e, 0x36, 0xdf, 0xb2, 0x70, 0x78, 0x56, 0xc3, 0x42, 0xff, 0xf7, 0x8f, 0x37, 0x95, 0x0, 0x26, 0xa, 0xac, 0x54, 0x72}},
  35. {Offset: 917504, Size: 0x20000, Hash: []uint8{0x96, 0x6b, 0x15, 0x6b, 0xc4, 0xf, 0x19, 0x18, 0xca, 0xbb, 0x5f, 0xd6, 0xbb, 0xa2, 0xc6, 0x2a, 0xac, 0xbb, 0x8a, 0xb9, 0xce, 0xec, 0x4c, 0xdb, 0x78, 0xec, 0x57, 0x5d, 0x33, 0xf9, 0x8e, 0xaf}},
  36. }
  37. var folders = []string{"default"}
  38. // Layout of the files: (indexes from the above array)
  39. // 12345678 - Required file
  40. // 02005008 - Existing file (currently in the index)
  41. // 02340070 - Temp file on the disk
  42. func TestHandleFile(t *testing.T) {
  43. // After the diff between required and existing we should:
  44. // Copy: 2, 5, 8
  45. // Pull: 1, 3, 4, 6, 7
  46. // Create existing file
  47. existingFile := protocol.FileInfo{
  48. Name: "filex",
  49. Flags: 0,
  50. Modified: 0,
  51. Blocks: []protocol.BlockInfo{
  52. blocks[0], blocks[2], blocks[0], blocks[0],
  53. blocks[5], blocks[0], blocks[0], blocks[8],
  54. },
  55. }
  56. // Create target file
  57. requiredFile := existingFile
  58. requiredFile.Blocks = blocks[1:]
  59. db := db.OpenMemory()
  60. m := NewModel(defaultConfig, protocol.LocalDeviceID, "device", "syncthing", "dev", db, nil)
  61. m.AddFolder(defaultFolderConfig)
  62. // Update index
  63. m.updateLocals("default", []protocol.FileInfo{existingFile})
  64. p := rwFolder{
  65. folder: "default",
  66. dir: "testdata",
  67. model: m,
  68. errors: make(map[string]string),
  69. errorsMut: sync.NewMutex(),
  70. }
  71. copyChan := make(chan copyBlocksState, 1)
  72. p.handleFile(requiredFile, copyChan, nil)
  73. // Receive the results
  74. toCopy := <-copyChan
  75. if len(toCopy.blocks) != 8 {
  76. t.Errorf("Unexpected count of copy blocks: %d != 8", len(toCopy.blocks))
  77. }
  78. for i, block := range toCopy.blocks {
  79. if string(block.Hash) != string(blocks[i+1].Hash) {
  80. t.Errorf("Block mismatch: %s != %s", block.String(), blocks[i+1].String())
  81. }
  82. }
  83. }
  84. func TestHandleFileWithTemp(t *testing.T) {
  85. // After diff between required and existing we should:
  86. // Copy: 2, 5, 8
  87. // Pull: 1, 3, 4, 6, 7
  88. // After dropping out blocks already on the temp file we should:
  89. // Copy: 5, 8
  90. // Pull: 1, 6
  91. // Create existing file
  92. existingFile := protocol.FileInfo{
  93. Name: "file",
  94. Flags: 0,
  95. Modified: 0,
  96. Blocks: []protocol.BlockInfo{
  97. blocks[0], blocks[2], blocks[0], blocks[0],
  98. blocks[5], blocks[0], blocks[0], blocks[8],
  99. },
  100. }
  101. // Create target file
  102. requiredFile := existingFile
  103. requiredFile.Blocks = blocks[1:]
  104. db := db.OpenMemory()
  105. m := NewModel(defaultConfig, protocol.LocalDeviceID, "device", "syncthing", "dev", db, nil)
  106. m.AddFolder(defaultFolderConfig)
  107. // Update index
  108. m.updateLocals("default", []protocol.FileInfo{existingFile})
  109. p := rwFolder{
  110. folder: "default",
  111. dir: "testdata",
  112. model: m,
  113. errors: make(map[string]string),
  114. errorsMut: sync.NewMutex(),
  115. }
  116. copyChan := make(chan copyBlocksState, 1)
  117. p.handleFile(requiredFile, copyChan, nil)
  118. // Receive the results
  119. toCopy := <-copyChan
  120. if len(toCopy.blocks) != 4 {
  121. t.Errorf("Unexpected count of copy blocks: %d != 4", len(toCopy.blocks))
  122. }
  123. for i, eq := range []int{1, 5, 6, 8} {
  124. if string(toCopy.blocks[i].Hash) != string(blocks[eq].Hash) {
  125. t.Errorf("Block mismatch: %s != %s", toCopy.blocks[i].String(), blocks[eq].String())
  126. }
  127. }
  128. }
  129. func TestCopierFinder(t *testing.T) {
  130. // After diff between required and existing we should:
  131. // Copy: 1, 2, 3, 4, 6, 7, 8
  132. // Since there is no existing file, nor a temp file
  133. // After dropping out blocks found locally:
  134. // Pull: 1, 5, 6, 8
  135. tempFile := filepath.Join("testdata", defTempNamer.TempName("file2"))
  136. err := os.Remove(tempFile)
  137. if err != nil && !os.IsNotExist(err) {
  138. t.Error(err)
  139. }
  140. // Create existing file
  141. existingFile := protocol.FileInfo{
  142. Name: defTempNamer.TempName("file"),
  143. Flags: 0,
  144. Modified: 0,
  145. Blocks: []protocol.BlockInfo{
  146. blocks[0], blocks[2], blocks[3], blocks[4],
  147. blocks[0], blocks[0], blocks[7], blocks[0],
  148. },
  149. }
  150. // Create target file
  151. requiredFile := existingFile
  152. requiredFile.Blocks = blocks[1:]
  153. requiredFile.Name = "file2"
  154. db := db.OpenMemory()
  155. m := NewModel(defaultConfig, protocol.LocalDeviceID, "device", "syncthing", "dev", db, nil)
  156. m.AddFolder(defaultFolderConfig)
  157. // Update index
  158. m.updateLocals("default", []protocol.FileInfo{existingFile})
  159. iterFn := func(folder, file string, index int32) bool {
  160. return true
  161. }
  162. // Verify that the blocks we say exist on file, really exist in the db.
  163. for _, idx := range []int{2, 3, 4, 7} {
  164. if m.finder.Iterate(folders, blocks[idx].Hash, iterFn) == false {
  165. t.Error("Didn't find block")
  166. }
  167. }
  168. p := rwFolder{
  169. folder: "default",
  170. dir: "testdata",
  171. model: m,
  172. errors: make(map[string]string),
  173. errorsMut: sync.NewMutex(),
  174. }
  175. copyChan := make(chan copyBlocksState)
  176. pullChan := make(chan pullBlockState, 4)
  177. finisherChan := make(chan *sharedPullerState, 1)
  178. // Run a single fetcher routine
  179. go p.copierRoutine(copyChan, pullChan, finisherChan)
  180. p.handleFile(requiredFile, copyChan, finisherChan)
  181. pulls := []pullBlockState{<-pullChan, <-pullChan, <-pullChan, <-pullChan}
  182. finish := <-finisherChan
  183. select {
  184. case <-pullChan:
  185. t.Fatal("Finisher channel has data to be read")
  186. case <-finisherChan:
  187. t.Fatal("Finisher channel has data to be read")
  188. default:
  189. }
  190. // Verify that the right blocks went into the pull list
  191. for i, eq := range []int{1, 5, 6, 8} {
  192. if string(pulls[i].block.Hash) != string(blocks[eq].Hash) {
  193. t.Errorf("Block %d mismatch: %s != %s", eq, pulls[i].block.String(), blocks[eq].String())
  194. }
  195. if string(finish.file.Blocks[eq-1].Hash) != string(blocks[eq].Hash) {
  196. t.Errorf("Block %d mismatch: %s != %s", eq, finish.file.Blocks[eq-1].String(), blocks[eq].String())
  197. }
  198. }
  199. // Verify that the fetched blocks have actually been written to the temp file
  200. blks, err := scanner.HashFile(tempFile, protocol.BlockSize, 0, nil)
  201. if err != nil {
  202. t.Log(err)
  203. }
  204. for _, eq := range []int{2, 3, 4, 7} {
  205. if string(blks[eq-1].Hash) != string(blocks[eq].Hash) {
  206. t.Errorf("Block %d mismatch: %s != %s", eq, blks[eq-1].String(), blocks[eq].String())
  207. }
  208. }
  209. finish.fd.Close()
  210. os.Remove(tempFile)
  211. }
  212. // Test that updating a file removes it's old blocks from the blockmap
  213. func TestCopierCleanup(t *testing.T) {
  214. iterFn := func(folder, file string, index int32) bool {
  215. return true
  216. }
  217. db := db.OpenMemory()
  218. m := NewModel(defaultConfig, protocol.LocalDeviceID, "device", "syncthing", "dev", db, nil)
  219. m.AddFolder(defaultFolderConfig)
  220. // Create a file
  221. file := protocol.FileInfo{
  222. Name: "test",
  223. Flags: 0,
  224. Modified: 0,
  225. Blocks: []protocol.BlockInfo{blocks[0]},
  226. }
  227. // Add file to index
  228. m.updateLocals("default", []protocol.FileInfo{file})
  229. if !m.finder.Iterate(folders, blocks[0].Hash, iterFn) {
  230. t.Error("Expected block not found")
  231. }
  232. file.Blocks = []protocol.BlockInfo{blocks[1]}
  233. file.Version = file.Version.Update(protocol.LocalDeviceID.Short())
  234. // Update index (removing old blocks)
  235. m.updateLocals("default", []protocol.FileInfo{file})
  236. if m.finder.Iterate(folders, blocks[0].Hash, iterFn) {
  237. t.Error("Unexpected block found")
  238. }
  239. if !m.finder.Iterate(folders, blocks[1].Hash, iterFn) {
  240. t.Error("Expected block not found")
  241. }
  242. file.Blocks = []protocol.BlockInfo{blocks[0]}
  243. file.Version = file.Version.Update(protocol.LocalDeviceID.Short())
  244. // Update index (removing old blocks)
  245. m.updateLocals("default", []protocol.FileInfo{file})
  246. if !m.finder.Iterate(folders, blocks[0].Hash, iterFn) {
  247. t.Error("Unexpected block found")
  248. }
  249. if m.finder.Iterate(folders, blocks[1].Hash, iterFn) {
  250. t.Error("Expected block not found")
  251. }
  252. }
  253. // Make sure that the copier routine hashes the content when asked, and pulls
  254. // if it fails to find the block.
  255. func TestLastResortPulling(t *testing.T) {
  256. db := db.OpenMemory()
  257. m := NewModel(defaultConfig, protocol.LocalDeviceID, "device", "syncthing", "dev", db, nil)
  258. m.AddFolder(defaultFolderConfig)
  259. // Add a file to index (with the incorrect block representation, as content
  260. // doesn't actually match the block list)
  261. file := protocol.FileInfo{
  262. Name: "empty",
  263. Flags: 0,
  264. Modified: 0,
  265. Blocks: []protocol.BlockInfo{blocks[0]},
  266. }
  267. m.updateLocals("default", []protocol.FileInfo{file})
  268. // Pretend that we are handling a new file of the same content but
  269. // with a different name (causing to copy that particular block)
  270. file.Name = "newfile"
  271. iterFn := func(folder, file string, index int32) bool {
  272. return true
  273. }
  274. // Check that that particular block is there
  275. if !m.finder.Iterate(folders, blocks[0].Hash, iterFn) {
  276. t.Error("Expected block not found")
  277. }
  278. p := rwFolder{
  279. folder: "default",
  280. dir: "testdata",
  281. model: m,
  282. errors: make(map[string]string),
  283. errorsMut: sync.NewMutex(),
  284. }
  285. copyChan := make(chan copyBlocksState)
  286. pullChan := make(chan pullBlockState, 1)
  287. finisherChan := make(chan *sharedPullerState, 1)
  288. // Run a single copier routine
  289. go p.copierRoutine(copyChan, pullChan, finisherChan)
  290. p.handleFile(file, copyChan, finisherChan)
  291. // Copier should hash empty file, realise that the region it has read
  292. // doesn't match the hash which was advertised by the block map, fix it
  293. // and ask to pull the block.
  294. <-pullChan
  295. // Verify that it did fix the incorrect hash.
  296. if m.finder.Iterate(folders, blocks[0].Hash, iterFn) {
  297. t.Error("Found unexpected block")
  298. }
  299. if !m.finder.Iterate(folders, scanner.SHA256OfNothing, iterFn) {
  300. t.Error("Expected block not found")
  301. }
  302. (<-finisherChan).fd.Close()
  303. os.Remove(filepath.Join("testdata", defTempNamer.TempName("newfile")))
  304. }
  305. func TestDeregisterOnFailInCopy(t *testing.T) {
  306. file := protocol.FileInfo{
  307. Name: "filex",
  308. Flags: 0,
  309. Modified: 0,
  310. Blocks: []protocol.BlockInfo{
  311. blocks[0], blocks[2], blocks[0], blocks[0],
  312. blocks[5], blocks[0], blocks[0], blocks[8],
  313. },
  314. }
  315. defer os.Remove("testdata/" + defTempNamer.TempName("filex"))
  316. db := db.OpenMemory()
  317. m := NewModel(defaultConfig, protocol.LocalDeviceID, "device", "syncthing", "dev", db, nil)
  318. m.AddFolder(defaultFolderConfig)
  319. emitter := NewProgressEmitter(defaultConfig)
  320. go emitter.Serve()
  321. p := rwFolder{
  322. folder: "default",
  323. dir: "testdata",
  324. model: m,
  325. queue: newJobQueue(),
  326. progressEmitter: emitter,
  327. errors: make(map[string]string),
  328. errorsMut: sync.NewMutex(),
  329. }
  330. // queue.Done should be called by the finisher routine
  331. p.queue.Push("filex", 0, 0)
  332. p.queue.Pop()
  333. if p.queue.lenProgress() != 1 {
  334. t.Fatal("Expected file in progress")
  335. }
  336. copyChan := make(chan copyBlocksState)
  337. pullChan := make(chan pullBlockState)
  338. finisherBufferChan := make(chan *sharedPullerState)
  339. finisherChan := make(chan *sharedPullerState)
  340. go p.copierRoutine(copyChan, pullChan, finisherBufferChan)
  341. go p.finisherRoutine(finisherChan)
  342. p.handleFile(file, copyChan, finisherChan)
  343. // Receive a block at puller, to indicate that at least a single copier
  344. // loop has been performed.
  345. toPull := <-pullChan
  346. // Wait until copier is trying to pass something down to the puller again
  347. time.Sleep(100 * time.Millisecond)
  348. // Close the file
  349. toPull.sharedPullerState.fail("test", os.ErrNotExist)
  350. // Unblock copier
  351. <-pullChan
  352. select {
  353. case state := <-finisherBufferChan:
  354. // At this point the file should still be registered with both the job
  355. // queue, and the progress emitter. Verify this.
  356. if p.progressEmitter.lenRegistry() != 1 || p.queue.lenProgress() != 1 || p.queue.lenQueued() != 0 {
  357. t.Fatal("Could not find file")
  358. }
  359. // Pass the file down the real finisher, and give it time to consume
  360. finisherChan <- state
  361. time.Sleep(100 * time.Millisecond)
  362. state.mut.Lock()
  363. stateFd := state.fd
  364. state.mut.Unlock()
  365. if stateFd != nil {
  366. t.Fatal("File not closed?")
  367. }
  368. if p.progressEmitter.lenRegistry() != 0 || p.queue.lenProgress() != 0 || p.queue.lenQueued() != 0 {
  369. t.Fatal("Still registered", p.progressEmitter.lenRegistry(), p.queue.lenProgress(), p.queue.lenQueued())
  370. }
  371. // Doing it again should have no effect
  372. finisherChan <- state
  373. time.Sleep(100 * time.Millisecond)
  374. if p.progressEmitter.lenRegistry() != 0 || p.queue.lenProgress() != 0 || p.queue.lenQueued() != 0 {
  375. t.Fatal("Still registered", p.progressEmitter.lenRegistry(), p.queue.lenProgress(), p.queue.lenQueued())
  376. }
  377. case <-time.After(time.Second):
  378. t.Fatal("Didn't get anything to the finisher")
  379. }
  380. }
  381. func TestDeregisterOnFailInPull(t *testing.T) {
  382. file := protocol.FileInfo{
  383. Name: "filex",
  384. Flags: 0,
  385. Modified: 0,
  386. Blocks: []protocol.BlockInfo{
  387. blocks[0], blocks[2], blocks[0], blocks[0],
  388. blocks[5], blocks[0], blocks[0], blocks[8],
  389. },
  390. }
  391. defer os.Remove("testdata/" + defTempNamer.TempName("filex"))
  392. db := db.OpenMemory()
  393. m := NewModel(defaultConfig, protocol.LocalDeviceID, "device", "syncthing", "dev", db, nil)
  394. m.AddFolder(defaultFolderConfig)
  395. emitter := NewProgressEmitter(defaultConfig)
  396. go emitter.Serve()
  397. p := rwFolder{
  398. folder: "default",
  399. dir: "testdata",
  400. model: m,
  401. queue: newJobQueue(),
  402. progressEmitter: emitter,
  403. errors: make(map[string]string),
  404. errorsMut: sync.NewMutex(),
  405. }
  406. // queue.Done should be called by the finisher routine
  407. p.queue.Push("filex", 0, 0)
  408. p.queue.Pop()
  409. if p.queue.lenProgress() != 1 {
  410. t.Fatal("Expected file in progress")
  411. }
  412. copyChan := make(chan copyBlocksState)
  413. pullChan := make(chan pullBlockState)
  414. finisherBufferChan := make(chan *sharedPullerState)
  415. finisherChan := make(chan *sharedPullerState)
  416. go p.copierRoutine(copyChan, pullChan, finisherBufferChan)
  417. go p.pullerRoutine(pullChan, finisherBufferChan)
  418. go p.finisherRoutine(finisherChan)
  419. p.handleFile(file, copyChan, finisherChan)
  420. // Receove at finisher, we shoud error out as puller has nowhere to pull
  421. // from.
  422. select {
  423. case state := <-finisherBufferChan:
  424. // At this point the file should still be registered with both the job
  425. // queue, and the progress emitter. Verify this.
  426. if p.progressEmitter.lenRegistry() != 1 || p.queue.lenProgress() != 1 || p.queue.lenQueued() != 0 {
  427. t.Fatal("Could not find file")
  428. }
  429. // Pass the file down the real finisher, and give it time to consume
  430. finisherChan <- state
  431. time.Sleep(100 * time.Millisecond)
  432. state.mut.Lock()
  433. stateFd := state.fd
  434. state.mut.Unlock()
  435. if stateFd != nil {
  436. t.Fatal("File not closed?")
  437. }
  438. if p.progressEmitter.lenRegistry() != 0 || p.queue.lenProgress() != 0 || p.queue.lenQueued() != 0 {
  439. t.Fatal("Still registered", p.progressEmitter.lenRegistry(), p.queue.lenProgress(), p.queue.lenQueued())
  440. }
  441. // Doing it again should have no effect
  442. finisherChan <- state
  443. time.Sleep(100 * time.Millisecond)
  444. if p.progressEmitter.lenRegistry() != 0 || p.queue.lenProgress() != 0 || p.queue.lenQueued() != 0 {
  445. t.Fatal("Still registered", p.progressEmitter.lenRegistry(), p.queue.lenProgress(), p.queue.lenQueued())
  446. }
  447. case <-time.After(time.Second):
  448. t.Fatal("Didn't get anything to the finisher")
  449. }
  450. }