CI / Test (ubuntu-latest) (push) Canceled after 0s
CI / Test (windows-latest) (push) Canceled after 0s
CI / Storage tests on PostgreSQL (push) Canceled after 0s
CI / Complement (federation off) (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
CI / Smoke test the binary (push) Canceled after 0s
Implements PLAN.md Phase 10. Simplified Sliding Sync (MSC4186) is served at the unstable org.matrix.simplified_msc3575 endpoint and advertised in /versions. Lists are sorted by activity and filtered by DM, invite, encryption, room type, space and tag; room subscriptions, required_state with wildcards, $ME and $LAZY, and the to_device, e2ee, account_data, receipts and typing extensions are supported. Per-connection state is kept in memory and an unknown pos answers M_UNKNOWN_POS. Threads and relations: m.relates_to is indexed on roomserver_events (migration 0012), /relations (with recursion) and /threads are served, and every event a timeline read returns carries its m.thread, m.replace and m.reference summaries in unsigned.m.relations. Notifications carry a thread ID (migration 0013): threaded receipts clear only their thread, and sync reports unread_thread_notifications when the filter asks. Spaces: /hierarchy walks a space breadth first, asking other servers about rooms this one is not in through the new federation hierarchy endpoint; room_summary describes one room. /search runs on FTS5 (sqlite, pocketbase) or tsvector (postgres), bounded to what each user may see, with context, profiles, state, grouping and paging. The PocketBase driver is real: the sqlite schema and store on an embedded PocketBase app's database, with media in its filesystem, local or S3 (database.pocketbase.s3). It runs the full storage test suite. Ops: OpenTelemetry tracing over OTLP/HTTP (tracing.*), with server spans per route, component spans, and trace propagation on federation, push and application service calls. New metrics for persisted events, waiting syncs, sliding sync connections and the database pool, with a Grafana dashboard. deploy/ adds a Compose setup (PostgreSQL, Prometheus, Grafana, Jaeger) and a Helm chart; cmd/warp-loadtest loads a server and reports request and delivery latencies. The load tester found a long-standing bug, fixed here: on a server where no account data had been written, every incremental /sync re-sent the push rules and returned at once, and an all-zero token was taken for an initial sync, so long polls became busy loops. The PostgreSQL migrations and search dialect compile but were not run against a live PostgreSQL in this change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
171 lines
6.3 KiB
Go
171 lines
6.3 KiB
Go
package setup_test
|
|
|
|
import (
|
|
"net/http"
|
|
"net/url"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/dariuszjaniak/warp/server/internal/config"
|
|
)
|
|
|
|
// The Phase 10 tests: the PocketBase driver and the new endpoints, through
|
|
// the whole stack.
|
|
|
|
// TestPocketBaseServer runs a server on the pocketbase driver: accounts,
|
|
// rooms, search and media, with the media landing in PocketBase's own
|
|
// filesystem rather than under media.base_path.
|
|
func TestPocketBaseServer(t *testing.T) {
|
|
dir := t.TempDir()
|
|
dataDir := filepath.Join(dir, "pb_data")
|
|
mediaDir := filepath.Join(dir, "media")
|
|
srv := newSigningServer(t, func(cfg *config.Config) {
|
|
cfg.Database.Driver = "pocketbase"
|
|
cfg.Database.ConnectionString = dataDir
|
|
cfg.Registration.Enabled = true
|
|
cfg.ClientAPI.RateLimit.Enabled = false
|
|
cfg.Media.BasePath = mediaDir
|
|
})
|
|
|
|
health := get(t, srv, http.MethodGet, "/healthz")
|
|
if health.Code != http.StatusOK || !strings.Contains(health.Body.String(), `"database":"pocketbase"`) {
|
|
t.Fatalf("healthz: %d %s", health.Code, health.Body.String())
|
|
}
|
|
|
|
token := registerThrough(t, srv, "alice")
|
|
rec := post(t, srv, "/_matrix/client/v3/createRoom", map[string]any{"name": "On PocketBase"}, token)
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("createRoom: %d %s", rec.Code, rec.Body.String())
|
|
}
|
|
roomID := decode[map[string]string](t, rec)["room_id"]
|
|
|
|
rec = send(t, srv, http.MethodPut,
|
|
"/_matrix/client/v3/rooms/"+url.PathEscape(roomID)+"/send/m.room.message/t1",
|
|
"application/json", []byte(`{"msgtype":"m.text","body":"stored in a pocket"}`), token, nil)
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("send: %d %s", rec.Code, rec.Body.String())
|
|
}
|
|
|
|
rec = post(t, srv, "/_matrix/client/v3/search", map[string]any{
|
|
"search_categories": map[string]any{"room_events": map[string]any{"search_term": "pocket"}},
|
|
}, token)
|
|
if rec.Code != http.StatusOK || !strings.Contains(rec.Body.String(), "stored in a pocket") {
|
|
t.Errorf("search: %d %s", rec.Code, rec.Body.String())
|
|
}
|
|
|
|
server, id := uploadThrough(t, srv, token, "text/plain", "note.txt", []byte("pocket media"))
|
|
rec = getWithToken(t, srv, "/_matrix/client/v1/media/download/"+server+"/"+id, token)
|
|
if rec.Code != http.StatusOK || rec.Body.String() != "pocket media" {
|
|
t.Fatalf("download: %d %q", rec.Code, rec.Body.String())
|
|
}
|
|
|
|
var found bool
|
|
_ = filepath.WalkDir(filepath.Join(dataDir, "storage", "warp_media"), func(_ string, d os.DirEntry, err error) error {
|
|
if err == nil && !d.IsDir() {
|
|
found = true
|
|
}
|
|
return nil
|
|
})
|
|
if !found {
|
|
t.Error("the upload is not in PocketBase's storage directory")
|
|
}
|
|
if _, err := os.Stat(mediaDir); !os.IsNotExist(err) {
|
|
t.Errorf("media.base_path was used: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestVersionsAdvertisesSlidingSync(t *testing.T) {
|
|
srv := newTestServer(t, nil)
|
|
rec := get(t, srv, http.MethodGet, "/_matrix/client/versions")
|
|
features := decode[map[string]any](t, rec)["unstable_features"].(map[string]any)
|
|
if features["org.matrix.simplified_msc3575"] != true {
|
|
t.Errorf("unstable_features = %v", features)
|
|
}
|
|
}
|
|
|
|
func TestPhase10RoutesAreWiredUp(t *testing.T) {
|
|
srv := newSigningServer(t, func(c *config.Config) {
|
|
c.Registration.Enabled = true
|
|
c.ClientAPI.RateLimit.Enabled = false
|
|
})
|
|
token := registerThrough(t, srv, "alice")
|
|
rec := post(t, srv, "/_matrix/client/v3/createRoom", map[string]any{
|
|
"creation_content": map[string]any{"type": "m.space"},
|
|
}, token)
|
|
roomID := decode[map[string]string](t, rec)["room_id"]
|
|
escaped := url.PathEscape(roomID)
|
|
|
|
for _, path := range []string{
|
|
"/_matrix/client/v1/rooms/" + escaped + "/hierarchy",
|
|
"/_matrix/client/v1/rooms/" + escaped + "/threads",
|
|
"/_matrix/client/v1/room_summary/" + escaped,
|
|
} {
|
|
if rec := getWithToken(t, srv, path, token); rec.Code != http.StatusOK {
|
|
t.Errorf("%s: %d %s", path, rec.Code, rec.Body.String())
|
|
}
|
|
}
|
|
rec = post(t, srv, "/_matrix/client/unstable/org.matrix.simplified_msc3575/sync", map[string]any{
|
|
"lists": map[string]any{"all": map[string]any{"ranges": [][2]int{{0, 5}}}},
|
|
}, token)
|
|
if rec.Code != http.StatusOK || !strings.Contains(rec.Body.String(), `"pos"`) {
|
|
t.Errorf("sliding sync: %d %s", rec.Code, rec.Body.String())
|
|
}
|
|
}
|
|
|
|
func TestServerMetrics(t *testing.T) {
|
|
srv := newSigningServer(t, nil)
|
|
token := registerThrough(t, srv, "alice")
|
|
if rec := post(t, srv, "/_matrix/client/v3/createRoom", map[string]any{}, token); rec.Code != http.StatusOK {
|
|
t.Fatalf("createRoom: %d", rec.Code)
|
|
}
|
|
body := get(t, srv, http.MethodGet, "/metrics").Body.String()
|
|
for _, want := range []string{
|
|
`warp_events_persisted_total{kind="state",origin="local"}`,
|
|
"warp_sync_waiting 0",
|
|
"warp_sync_sliding_connections 0",
|
|
"warp_federation_enabled 0",
|
|
"go_sql_open_connections",
|
|
} {
|
|
if !strings.Contains(body, want) {
|
|
t.Errorf("/metrics has no %s", want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestIdleSyncLongPolls is the regression test for two ways an idle
|
|
// /sync came back at once instead of waiting, which made every client's
|
|
// long poll a busy loop: push rules sent again on every sync of a server
|
|
// with no account data written yet, and an all-zero token taken for a
|
|
// first sync on a server whose streams had not moved at all.
|
|
func TestIdleSyncLongPolls(t *testing.T) {
|
|
for _, withRoom := range []bool{false, true} {
|
|
t.Run(map[bool]string{false: "empty server", true: "with a room"}[withRoom], func(t *testing.T) {
|
|
srv := newSigningServer(t, nil)
|
|
token := registerThrough(t, srv, "alice")
|
|
if withRoom {
|
|
if rec := post(t, srv, "/_matrix/client/v3/createRoom", map[string]any{}, token); rec.Code != http.StatusOK {
|
|
t.Fatalf("createRoom: %d", rec.Code)
|
|
}
|
|
}
|
|
|
|
first := decode[map[string]any](t, getWithToken(t, srv, "/_matrix/client/v3/sync", token))
|
|
since, _ := first["next_batch"].(string)
|
|
|
|
body := decode[map[string]any](t, getWithToken(t, srv, "/_matrix/client/v3/sync?timeout=0&since="+url.QueryEscape(since), token))
|
|
accountData, _ := body["account_data"].(map[string]any)
|
|
if events, _ := accountData["events"].([]any); len(events) != 0 {
|
|
t.Errorf("an idle incremental sync sent account data again: %d events", len(events))
|
|
}
|
|
|
|
start := time.Now()
|
|
getWithToken(t, srv, "/_matrix/client/v3/sync?timeout=1000&since="+url.QueryEscape(since), token)
|
|
if waited := time.Since(start); waited < 900*time.Millisecond {
|
|
t.Errorf("an idle sync returned after %s instead of waiting out its timeout", waited)
|
|
}
|
|
})
|
|
}
|
|
}
|