mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-17 15:46:44 +00:00
Fix transfer stopping
This commit is contained in:
@ -19,6 +19,7 @@ package transfer
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
a "github.com/stretchr/testify/assert"
|
||||
@ -104,6 +105,28 @@ func TestProgressFatalError(t *testing.T) {
|
||||
r.NotPanics(t, func() { progress.addMessage("msg", nil) })
|
||||
}
|
||||
|
||||
func TestFailUnpauseAndStops(t *testing.T) {
|
||||
progress := newProgress(log, nil)
|
||||
drainProgressUpdateChannel(&progress)
|
||||
|
||||
progress.Pause("pausing")
|
||||
progress.fatal(errors.New("fatal error"))
|
||||
|
||||
r.Nil(t, progress.updateCh)
|
||||
r.True(t, progress.isStopped)
|
||||
r.False(t, progress.IsPaused())
|
||||
r.Eventually(t, progress.shouldStop, 2*time.Millisecond, time.Millisecond)
|
||||
}
|
||||
|
||||
func TestStopClosesUpdates(t *testing.T) {
|
||||
progress := newProgress(log, nil)
|
||||
ch := progress.updateCh
|
||||
|
||||
progress.Stop()
|
||||
r.Nil(t, progress.updateCh)
|
||||
r.PanicsWithError(t, "send on closed channel", func() { ch <- struct{}{} })
|
||||
}
|
||||
|
||||
func drainProgressUpdateChannel(progress *Progress) {
|
||||
// updateCh is not needed to drain under tests - timeout is implemented.
|
||||
// But timeout takes time which would slow down tests.
|
||||
|
||||
Reference in New Issue
Block a user