summaryrefslogtreecommitdiff
path: root/internal/mapr/client/session_state_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-07-22 23:51:18 +0300
committerPaul Buetow <paul@buetow.org>2026-07-22 23:51:18 +0300
commit849951be1d1a7ee9f9302006ccb187bf5b4e36f3 (patch)
tree496c924a03a9ea6212e29bb4699e268066ebad81 /internal/mapr/client/session_state_test.go
parentbf78b3abffee6d49c08ca2980156afc455994969 (diff)
feat: DTail fork — server/client feature development
Squashed development of the snonux/dtail fork's product code (internal/, cmd/) since diverging from mimecast/dtail. Major areas: - Read/output path: the former "turbo" channel-less path is now the single, default server-side read/output path for cat/grep/tail and MapReduce; the old channel-based path and its config/env toggles were removed. - MapReduce: single aggregate implementation (server + serverless) fed directly by a processor pipeline, with input-exhausted finalization via the shutdown coordinator; high-concurrency and data-race fixes. - Journal source reads (journal:unit.service) via journalctl, Linux-gated behind a journal-v1 capability. - Auth-key fast reconnect: in-memory per-user public-key cache with TTL/max-keys, registered over an authenticated session (AUTHKEY), checked before authorized_keys. - Interactive query reload (--interactive-query) with SESSION START/UPDATE generation boundaries and capability negotiation. - Client-side deadlines: --timeout / --shutdownAfter as context deadlines; follow shutdown handling. - Client logging: diagnostics-only daily log by default, opt-in payload tee via --log-payload. - Numerous correctness fixes (buffer-pool double-recycle races, EOF-sentinel leaks, glob-expansion cap, TOCTOU in CSV parsing) with accompanying unit tests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'internal/mapr/client/session_state_test.go')
-rw-r--r--internal/mapr/client/session_state_test.go81
1 files changed, 81 insertions, 0 deletions
diff --git a/internal/mapr/client/session_state_test.go b/internal/mapr/client/session_state_test.go
new file mode 100644
index 0000000..f43ca70
--- /dev/null
+++ b/internal/mapr/client/session_state_test.go
@@ -0,0 +1,81 @@
+package client
+
+import (
+ "testing"
+
+ "github.com/mimecast/dtail/internal/mapr"
+)
+
+func TestSessionStateCommitQueryResetsGenerationAndResults(t *testing.T) {
+ query := mustSessionStateQuery(t, "select count(status) from stats group by status")
+ state := NewSessionState(query)
+
+ initial := state.Snapshot()
+ group := mapr.NewGroupSet()
+ set := group.GetSet("ERROR")
+ set.Samples = 1
+ set.FValues[query.Select[0].FieldStorage] = 1
+ if err := initial.GlobalGroup.Merge(query, group); err != nil {
+ t.Fatalf("Merge() error = %v", err)
+ }
+ if changed, ok := state.CommitRenderedResult(initial.Generation, "old-result"); !ok || !changed {
+ t.Fatalf("CommitRenderedResult() = changed:%v ok:%v, want changed and ok", changed, ok)
+ }
+
+ rawQuery := "select count(status) from warnings group by status"
+ updatedQuery, err := state.CommitQuery(rawQuery, 3)
+ if err != nil {
+ t.Fatalf("CommitQuery() error = %v", err)
+ }
+ if updatedQuery == nil || updatedQuery.RawQuery != rawQuery {
+ t.Fatalf("unexpected updated query: %#v", updatedQuery)
+ }
+
+ select {
+ case <-state.Changes():
+ default:
+ t.Fatalf("expected change notification after CommitQuery")
+ }
+
+ updated := state.Snapshot()
+ if updated.Generation != 3 {
+ t.Fatalf("generation = %d, want 3", updated.Generation)
+ }
+ if updated.Query == nil || updated.Query.RawQuery != rawQuery {
+ t.Fatalf("unexpected query after commit: %#v", updated.Query)
+ }
+ if !updated.GlobalGroup.IsEmpty() {
+ t.Fatalf("expected committed global group to be reset")
+ }
+ if updated.LastResult != "" {
+ t.Fatalf("last result = %q, want empty", updated.LastResult)
+ }
+}
+
+func TestSessionStateCommitQueryRejectsInvalidQuery(t *testing.T) {
+ query := mustSessionStateQuery(t, "select count(status) from stats group by status")
+ state := NewSessionState(query)
+ before := state.Snapshot()
+
+ if _, err := state.CommitQuery("select from", 5); err == nil {
+ t.Fatalf("expected CommitQuery() to reject invalid query")
+ }
+
+ after := state.Snapshot()
+ if after.Generation != before.Generation {
+ t.Fatalf("generation changed on invalid query: got %d want %d", after.Generation, before.Generation)
+ }
+ if after.Query == nil || after.Query.RawQuery != before.Query.RawQuery {
+ t.Fatalf("query changed on invalid query: before=%#v after=%#v", before.Query, after.Query)
+ }
+}
+
+func mustSessionStateQuery(t *testing.T, queryStr string) *mapr.Query {
+ t.Helper()
+
+ query, err := mapr.NewQuery(queryStr)
+ if err != nil {
+ t.Fatalf("NewQuery(%q) error = %v", queryStr, err)
+ }
+ return query
+}