simplify send message bg helper
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -88,24 +88,25 @@ func storeTestMessage(t *testing.T, peer *client.Peer, text string) {
|
||||
|
||||
// pushAndMarkSent pushes a send job for the given peer and marks it as delivered
|
||||
// by the given server. Returns the job after the status update.
|
||||
// It mirrors the correct app usage: call GetPeerLastMessageDbInfo immediately
|
||||
// after storing to populate MessageDbFile and MessageDbId on the job.
|
||||
// The outbox file is named {dbFile}_{dbId} so that ProcessSentMessages can
|
||||
// recover the message DB location from the filename, matching the convention
|
||||
// used by CreateUserMessageAndSendJob.
|
||||
func pushAndMarkSent(t *testing.T, dir string, peer *client.Peer, srv client.Server) *client.SendJob {
|
||||
t.Helper()
|
||||
|
||||
dbFile, dbId, errTxt, err := GetPeerLastMessageDbInfo(peer.Uid)
|
||||
require.NoError(t, err, errTxt)
|
||||
dbFile := peer.LastMessage.Dbfile
|
||||
dbId := peer.LastMessage.Dbid
|
||||
|
||||
msgFile := filepath.Join(dir, fmt.Sprintf("msg-%d.bin", dbId))
|
||||
outboxDir := filepath.Join(dir, "outbox")
|
||||
require.NoError(t, os.MkdirAll(outboxDir, 0700))
|
||||
msgFile := filepath.Join(outboxDir, fmt.Sprintf("%s_%d", dbFile, dbId))
|
||||
require.NoError(t, os.WriteFile(msgFile, []byte("packed-server-message"), 0600))
|
||||
|
||||
require.NoError(t, client.PushSendJob(dir, &client.SendJob{
|
||||
Queue: peer.Uid,
|
||||
File: msgFile,
|
||||
MessageDbFile: dbFile,
|
||||
MessageDbId: dbId,
|
||||
Servers: []client.Server{srv},
|
||||
Timeout: 60,
|
||||
Queue: peer.Uid,
|
||||
File: msgFile,
|
||||
Servers: []client.Server{srv},
|
||||
Timeout: 60,
|
||||
}))
|
||||
|
||||
job, _, err := client.PeekSendJob(dir, peer.Uid)
|
||||
@@ -177,19 +178,19 @@ func TestProcessSentMessages_SkipsJobWithoutDeliveryInfo(t *testing.T) {
|
||||
|
||||
storeTestMessage(t, peer, "incomplete job")
|
||||
|
||||
dbFile, dbId, errTxt, err := GetPeerLastMessageDbInfo(peer.Uid)
|
||||
require.NoError(t, err, errTxt)
|
||||
dbFile := peer.LastMessage.Dbfile
|
||||
dbId := peer.LastMessage.Dbid
|
||||
|
||||
msgFile := filepath.Join(dir, "msg.bin")
|
||||
outboxDir := filepath.Join(dir, "outbox")
|
||||
require.NoError(t, os.MkdirAll(outboxDir, 0700))
|
||||
msgFile := filepath.Join(outboxDir, fmt.Sprintf("%s_%d", dbFile, dbId))
|
||||
require.NoError(t, os.WriteFile(msgFile, []byte("packed"), 0600))
|
||||
|
||||
require.NoError(t, client.PushSendJob(dir, &client.SendJob{
|
||||
Queue: peer.Uid,
|
||||
File: msgFile,
|
||||
MessageDbFile: dbFile,
|
||||
MessageDbId: dbId,
|
||||
Servers: []client.Server{{Url: "http://test-server.example"}},
|
||||
Timeout: 60,
|
||||
Queue: peer.Uid,
|
||||
File: msgFile,
|
||||
Servers: []client.Server{{Url: "http://test-server.example"}},
|
||||
Timeout: 60,
|
||||
}))
|
||||
|
||||
job, _, err := client.PeekSendJob(dir, peer.Uid)
|
||||
@@ -225,10 +226,10 @@ func TestProcessSentMessages_EmptyQueues(t *testing.T) {
|
||||
assert.Equal(t, 0, updated, "empty queues → 0 updates")
|
||||
}
|
||||
|
||||
// TestProcessSentMessages_MissingDbInfo verifies that a job with blank
|
||||
// MessageDbFile or zero MessageDbId is rejected with a clear error, not silently
|
||||
// treated as successful.
|
||||
func TestProcessSentMessages_MissingDbInfo(t *testing.T) {
|
||||
// TestProcessSentMessages_UnparseableFilename verifies that a job whose filename
|
||||
// does not follow the {dbFile}_{dbId} convention is skipped with a logged error
|
||||
// and not counted as updated.
|
||||
func TestProcessSentMessages_UnparseableFilename(t *testing.T) {
|
||||
dir, id := setupMsgHelperConfig(t)
|
||||
|
||||
peer := newFullyKeyedPeer(t, "peer-uid-nodbinfo")
|
||||
@@ -236,10 +237,10 @@ func TestProcessSentMessages_MissingDbInfo(t *testing.T) {
|
||||
|
||||
storeTestMessage(t, peer, "the real message")
|
||||
|
||||
msgFile := filepath.Join(dir, "msg.bin")
|
||||
// A filename with no underscore cannot be parsed as {dbFile}_{dbId}.
|
||||
msgFile := filepath.Join(dir, "badname.bin")
|
||||
require.NoError(t, os.WriteFile(msgFile, []byte("packed"), 0600))
|
||||
|
||||
// Push a job WITHOUT MessageDbFile / MessageDbId — the old broken pattern.
|
||||
require.NoError(t, client.PushSendJob(dir, &client.SendJob{
|
||||
Queue: peer.Uid,
|
||||
File: msgFile,
|
||||
|
||||
Reference in New Issue
Block a user