"path/filepath"
"strings"
"testing"
+ "testing/synctest"
"time"
"github.com/stretchr/testify/require"
require.Equal(t, data, saved)
}
+func TestWhatsAppRunCancellationEndsAnImageDownload(t *testing.T) {
+ synctest.Test(t, func(t *testing.T) {
+ test := whatsappRetryTest(t)
+ test.fake.downloadWait = time.Hour
+ test.start(t)
+ synctest.Wait()
+
+ acknowledged := make(chan bool, 1)
+ go func() {
+ acknowledged <- test.fake.Emit(whatsappImageTestEvent(whatsappTestAna, "Keep this caption."))
+ }()
+
+ synctest.Wait()
+
+ select {
+ case <-acknowledged:
+ t.Fatal("download ended before daemon cancellation")
+ default:
+ }
+
+ test.cancel()
+ require.True(t, <-acknowledged)
+ require.NoError(t, <-test.done)
+ require.Empty(t, test.fake.Downloads())
+ require.Contains(t, test.logs.String(), "context canceled")
+ require.NoError(t, test.whatsapp.state.CloseAll())
+ require.Equal(t, "(image not downloaded)\nKeep this caption.", test.whatsapp.state.Closed()[0].Messages[0].Text)
+ })
+}
+
func TestWhatsAppImageFailureKeepsTheBatchMoving(t *testing.T) {
dir := t.TempDir()
whatsappTestSession(t, dir, true)