Git designed for AI agents.
tests: the checkpoint stamp checked against the snapshot, the server log of a failed e2e test
Federico Eliadab9e9449a59
diff --git a/internal/graft/corestore/sqlstore/checkpoint.go b/internal/graft/corestore/sqlstore/checkpoint.goindex d1226e1..27253f5 100644--- a/internal/graft/corestore/sqlstore/checkpoint.go+++ b/internal/graft/corestore/sqlstore/checkpoint.go@@ -126,6 +126,9 @@ func (s *Store) CreateCheckpoint(ctx context.Context, repoID int64, in corestorereturn fmt.Errorf("insert checkpoint references: %w", err)}}+ if s.snapshotWritten != nil {+ s.snapshotWritten()+ }// The last statements (integrated review, final minor 1): the age of a// checkpoint (C_gc, C_sync) counts from created_at, and the pack'sdiff --git a/internal/graft/corestore/sqlstore/checkpoint_large_test.go b/internal/graft/corestore/sqlstore/checkpoint_large_test.goindex dc7276d..16e07c3 100644--- a/internal/graft/corestore/sqlstore/checkpoint_large_test.go+++ b/internal/graft/corestore/sqlstore/checkpoint_large_test.go@@ -3,6 +3,7 @@ package sqlstore_testimport ("context""fmt"+ "sync""testing""time"@@ -58,6 +59,15 @@ func TestCheckpointOfManyReferences(t *testing.T) {}}()+ // The time the snapshot is written, on the last attempt of the record's transaction.+ var snapshotMu sync.Mutex+ var snapshotWritten time.Time+ s.SetSnapshotWrittenHook(func() {+ snapshotMu.Lock()+ defer snapshotMu.Unlock()+ snapshotWritten = time.Now()+ })+began := time.Now()_, created, err := s.CreateCheckpoint(ctx, repo.ID, corestore.CheckpointInput{Seq: 1, Refs: refs, PackKey: ownedKey(repo.ID, "large checkpoint"), PackDeadline: time.Now().Add(time.Hour), PackBytes: 1,@@ -76,13 +86,16 @@ func TestCheckpointOfManyReferences(t *testing.T) {require.Equal(t, refs, got)// created_at is stamped after the snapshot (final minor 1): it is not- // the time the record began. The database runs on this host, so its- // clock is the test's.+ // the time the record began, but a time after the snapshot was written.+ // The database runs on this host, so its clock is the test's.cp, ok, err := s.NewestCheckpoint(ctx, repo.ID)require.NoError(t, err)require.True(t, ok)- require.True(t, cp.CreatedAt.After(began.Add(took/2)),- "created_at %s, record from %s for %s", cp.CreatedAt, began, took)+ snapshotMu.Lock()+ defer snapshotMu.Unlock()+ require.False(t, snapshotWritten.IsZero())+ require.True(t, cp.CreatedAt.After(snapshotWritten),+ "created_at %s, snapshot written at %s, record from %s for %s", cp.CreatedAt, snapshotWritten, began, took)})}diff --git a/internal/graft/corestore/sqlstore/export_test.go b/internal/graft/corestore/sqlstore/export_test.goindex e287006..d616a99 100644--- a/internal/graft/corestore/sqlstore/export_test.go+++ b/internal/graft/corestore/sqlstore/export_test.go@@ -14,6 +14,12 @@ func OpenV010(ctx context.Context, dsn string) (*Store, error) {return open(ctx, dsn, 1)}+// SetSnapshotWrittenHook installs fn as the hook that CreateCheckpoint of s+// calls once the reference snapshot is written, before created_at is stamped.+func (s *Store) SetSnapshotWrittenHook(fn func()) {+ s.snapshotWritten = fn+}+// SetRetryHook installs fn as the hook called for every retried transaction and// returns the function that removes it.func SetRetryHook(fn func(err error)) (restore func()) {diff --git a/internal/graft/corestore/sqlstore/store.go b/internal/graft/corestore/sqlstore/store.goindex c7231f3..627f237 100644--- a/internal/graft/corestore/sqlstore/store.go+++ b/internal/graft/corestore/sqlstore/store.go@@ -71,6 +71,9 @@ type Store struct {// writers queues the write transactions on SQLite (nil on Postgres, whose// row locks queue their waiters themselves); see writeQueue.writers *writeQueue+ // snapshotWritten, when set by a test, is called by CreateCheckpoint once+ // the reference snapshot is written, before created_at is stamped.+ snapshotWritten func()}var _ corestore.MetaStore = (*Store)(nil)diff --git a/internal/graft/e2e/storage_localrefs_test.go b/internal/graft/e2e/storage_localrefs_test.goindex cb40292..b215730 100644--- a/internal/graft/e2e/storage_localrefs_test.go+++ b/internal/graft/e2e/storage_localrefs_test.go@@ -153,6 +153,18 @@ func (n *realNode) spawn(t *testing.T, env ...string) {cmd.Stderr = logFilerequire.NoError(t, cmd.Start())+ // A failing test shows how the server process ended and its log, which its temporary+ // directory would otherwise take with it: a request that ends with EOF or Unavailable says+ // only that the process went away. It runs after the cleanup below that stops the process+ // and waits for it (cleanups run in reverse order), so the process state is final.+ logPath := n.logPath+ t.Cleanup(func() {+ if t.Failed() {+ content, err := os.ReadFile(logPath)+ t.Logf("server process %s, log %s (read error: %v):\n%s", cmd.ProcessState, logPath, err, content)+ }+ })+exited := make(chan struct{})go func() {_ = cmd.Wait()