(t *testing.T)
| 52 | } |
| 53 | |
| 54 | func TestProgressEmitter(t *testing.T) { |
| 55 | ctx, cancel := context.WithCancel(context.Background()) |
| 56 | evLogger := events.NewLogger() |
| 57 | go evLogger.Serve(ctx) |
| 58 | defer cancel() |
| 59 | |
| 60 | w := evLogger.Subscribe(events.DownloadProgress) |
| 61 | |
| 62 | c, cfgCancel := newConfigWrapper(config.Configuration{Version: config.CurrentVersion}) |
| 63 | defer os.Remove(c.ConfigPath()) |
| 64 | defer cfgCancel() |
| 65 | waiter, err := c.Modify(func(cfg *config.Configuration) { |
| 66 | cfg.Options.ProgressUpdateIntervalS = 60 // irrelevant, but must be positive |
| 67 | }) |
| 68 | if err != nil { |
| 69 | t.Fatal(err) |
| 70 | } |
| 71 | waiter.Wait() |
| 72 | |
| 73 | p := NewProgressEmitter(c, evLogger) |
| 74 | go p.Serve(ctx) |
| 75 | p.interval = 0 |
| 76 | |
| 77 | expectTimeout(w, t) |
| 78 | |
| 79 | s := sharedPullerState{ |
| 80 | updated: time.Now(), |
| 81 | } |
| 82 | p.Register(&s) |
| 83 | |
| 84 | expectEvent(w, t, 1) |
| 85 | expectTimeout(w, t) |
| 86 | |
| 87 | s.copyDone(protocol.BlockInfo{}) |
| 88 | |
| 89 | expectEvent(w, t, 1) |
| 90 | expectTimeout(w, t) |
| 91 | |
| 92 | s.copiedFromOrigin(1) |
| 93 | |
| 94 | expectEvent(w, t, 1) |
| 95 | expectTimeout(w, t) |
| 96 | |
| 97 | s.pullStarted() |
| 98 | |
| 99 | expectEvent(w, t, 1) |
| 100 | expectTimeout(w, t) |
| 101 | |
| 102 | s.pullDone(protocol.BlockInfo{}) |
| 103 | |
| 104 | expectEvent(w, t, 1) |
| 105 | expectTimeout(w, t) |
| 106 | |
| 107 | p.Deregister(&s) |
| 108 | |
| 109 | expectEvent(w, t, 0) |
| 110 | expectTimeout(w, t) |
| 111 | } |
nothing calls this directly
no test coverage detected