The test of a private batch gave its two messages with 50 ms of real
quiet time between them, so on a loaded machine the first message closed
its batch alone and the test failed. The messages now come during a
catch-up, which holds the batch open until its end, so the test no
longer depends on the speed of the machine.
The test of a long disconnection waits 300 ms before the notice and 400
ms for a notice that must not come, so that a slow machine does not give
a notice between two events of the test.
Issue:
6f69ca1
whatsappTestSession(t, dir, true)
clock := newTestClock()
whatsapp, fake, _ := whatsappStartTest(t, dir, clock)
whatsappTestSession(t, dir, true)
clock := newTestClock()
whatsapp, fake, _ := whatsappStartTest(t, dir, clock)
- whatsapp.noticeDelay = 50 * time.Millisecond
+ whatsapp.noticeDelay = 300 * time.Millisecond
socket, _ := daemonStartTestWithWhatsApp(t, newModelFake(t), nil, whatsapp)
client := terminalStartTestClient(t, socket)
client.WaitFor(t, "[connected to OneChat]")
socket, _ := daemonStartTestWithWhatsApp(t, newModelFake(t), nil, whatsapp)
client := terminalStartTestClient(t, socket)
client.WaitFor(t, "[connected to OneChat]")
require.True(t, fake.Emit(&events.Connected{}))
require.True(t, fake.Emit(&events.Disconnected{}))
require.True(t, fake.Emit(&events.Connected{}))
require.True(t, fake.Emit(&events.Connected{}))
require.True(t, fake.Emit(&events.Disconnected{}))
require.True(t, fake.Emit(&events.Connected{}))
- time.Sleep(100 * time.Millisecond)
+ time.Sleep(400 * time.Millisecond)
require.Equal(t, "[connected to OneChat]\n", client.Output())
clock.now = clock.now.Add(time.Hour)
require.Equal(t, "[connected to OneChat]\n", client.Output())
clock.now = clock.now.Add(time.Hour)
require.True(t, fake.Emit(&events.Disconnected{}))
client.WaitFor(t, "WhatsApp is disconnected since 2026-01-01 13:00. OneChat tries again.\n")
require.True(t, fake.Emit(&events.Disconnected{}))
require.True(t, fake.Emit(&events.Disconnected{}))
client.WaitFor(t, "WhatsApp is disconnected since 2026-01-01 13:00. OneChat tries again.\n")
require.True(t, fake.Emit(&events.Disconnected{}))
- time.Sleep(100 * time.Millisecond)
+ time.Sleep(400 * time.Millisecond)
require.True(t, fake.Emit(&events.Connected{}))
client.WaitFor(t, "WhatsApp is connected again.\n")
require.True(t, fake.Emit(&events.Connected{}))
client.WaitFor(t, "WhatsApp is connected again.\n")
socket, memory := daemonStartTestWithWhatsApp(t, server, bot, whatsapp)
client := terminalStartTestClient(t, socket)
client.WaitFor(t, "[connected to OneChat]")
socket, memory := daemonStartTestWithWhatsApp(t, server, bot, whatsapp)
client := terminalStartTestClient(t, socket)
client.WaitFor(t, "[connected to OneChat]")
- whatsappTestConnect(t, fake)
+ // The catch-up holds the batch open until its end, so the two messages
+ // form one batch also on a slow machine.
+ require.True(t, fake.Emit(&events.Connected{}))
at := time.Date(2026, 1, 1, 12, 0, 0, 0, time.UTC)
require.True(t, fake.Emit(whatsappTestMessage(whatsappTestAna, whatsappTestAna, "m1", "Are you at home?", at)))
require.True(t, fake.Emit(whatsappTestMessage(whatsappTestAna, whatsappTestOwn, "m2", "Yes", at)))
at := time.Date(2026, 1, 1, 12, 0, 0, 0, time.UTC)
require.True(t, fake.Emit(whatsappTestMessage(whatsappTestAna, whatsappTestAna, "m1", "Are you at home?", at)))
require.True(t, fake.Emit(whatsappTestMessage(whatsappTestAna, whatsappTestOwn, "m2", "Yes", at)))
+ require.True(t, fake.Emit(&events.OfflineSyncCompleted{}))
text := "[WhatsApp] Ana Souza, private chat 15550002222@s.whatsapp.net, Thursday 2026-01-01\n12:00 Ana Souza: Are you at home?\n12:00 You: Yes\n" + whatsappBatchEmptyReply
client.WaitFor(t, text+"\n[working]\n[done]\n")
text := "[WhatsApp] Ana Souza, private chat 15550002222@s.whatsapp.net, Thursday 2026-01-01\n12:00 Ana Souza: Are you at home?\n12:00 You: Yes\n" + whatsappBatchEmptyReply
client.WaitFor(t, text+"\n[working]\n[done]\n")