simplify send message bg helper
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
ycc
2026-03-01 21:15:17 +01:00
parent 7d06f0ff3e
commit 0fdf5dd9c7
5 changed files with 171 additions and 130 deletions

View File

@@ -6,6 +6,8 @@ import (
"net/http/httptest"
"os"
"path/filepath"
"strconv"
"strings"
"sync/atomic"
"testing"
"time"
@@ -190,20 +192,44 @@ func TestAttemptSendJob_SkipsExhaustedServer(t *testing.T) {
// --- integration tests --------------------------------------------------
// TestWriteSendJob verifies the thin WriteSendJob wrapper enqueues the job.
func TestWriteSendJob(t *testing.T) {
dir := t.TempDir()
err := WriteSendJob(dir, &client.SendJob{
Queue: "q1",
File: "/tmp/f",
Servers: serverSlice("http://s1"),
})
// TestCreateUserMessageAndSendJob verifies that the packed message is written to
// outbox/{dbFile}_{dbId} and a pending send job is enqueued for the peer.
func TestCreateUserMessageAndSendJob(t *testing.T) {
dir, id := setupMsgHelperConfig(t)
peer := newFullyKeyedPeer(t, "peer-create-send")
require.NoError(t, id.Peers.StorePeer(peer))
srv := newTestServer(t, "http://test-srv.example")
err := CreateUserMessageAndSendJob(
dir,
"hello from integration",
"peer-create-send",
"",
nil,
[]client.Server{srv},
60,
)
require.NoError(t, err)
got, _, err := client.PeekSendJob(dir, "q1")
// A pending job must be in the queue.
job, _, err := client.PeekSendJob(dir, "peer-create-send")
require.NoError(t, err)
require.NotNil(t, got)
assert.Equal(t, "/tmp/f", got.File)
require.NotNil(t, job, "a send job must be enqueued")
// The outbox file must exist under storagePath/outbox/.
assert.FileExists(t, job.File)
assert.True(t, strings.HasPrefix(job.File, filepath.Join(dir, "outbox")),
"outbox file must be under storagePath/outbox/")
// The basename must follow the {dbFile}_{dbId} naming convention.
base := filepath.Base(job.File)
sep := strings.LastIndex(base, "_")
require.Greater(t, sep, 0, "filename must contain an underscore separating dbFile from dbId")
dbId, parseErr := strconv.ParseInt(base[sep+1:], 10, 64)
assert.NoError(t, parseErr, "suffix after underscore must be a numeric db ID")
assert.Greater(t, dbId, int64(0), "db ID must be positive")
}
// TestProcessSendQueues_Success verifies that a pending job is delivered and