Skip to content

Commit

Permalink
refactor the tests into two suites - existing default and one with Se…
Browse files Browse the repository at this point in the history
…ssions enabled
  • Loading branch information
lambrospetrou committed Sep 3, 2024
1 parent eadfe5e commit 4b1c31e
Show file tree
Hide file tree
Showing 7 changed files with 764 additions and 680 deletions.
16 changes: 12 additions & 4 deletions src/cloudflare/internal/d1-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,16 @@ type ResultsFormat = 'ARRAY_OF_OBJECTS' | 'ROWS_AND_COLUMNS' | 'NONE';

type D1SessionCommitTokenOrConstraint = string;
type D1SessionCommitToken = string;
const D1_SESSION_CONSTRAINT_FIRST_PRIMARY = "first-primary";
const D1_SESSION_CONSTRAINT_FIRST_UNCONSTRAINED = "first-unconstrained";

// TODO Figure out what header to use.
// Indicates that the first query should go to the primary, and the rest queries
// using the same D1DatabaseSession will go to any replica that is consistent with
// the commit token maintained by the session (returned by the first query).
const D1_SESSION_CONSTRAINT_FIRST_PRIMARY = 'first-primary';
// Indicates that the first query can go anywhere (primary or replica), and the rest queries
// using the same D1DatabaseSession will go to any replica that is consistent with
// the commit token maintained by the session (returned by the first query).
const D1_SESSION_CONSTRAINT_FIRST_UNCONSTRAINED = 'first-unconstrained';

// Parsed by the D1 eyeball worker.
const D1_SESSION_COMMIT_TOKEN_HTTP_HEADER = 'x-cf-d1-session-commit-token';

class D1Database {
Expand Down Expand Up @@ -208,6 +214,8 @@ class D1DatabaseSession {
const newCommitToken = resp.headers.get(
D1_SESSION_COMMIT_TOKEN_HTTP_HEADER
);
// TODO(soon): Add validation of the received commit token, in case we sent a commit token,
// otherwise sessions functionality could be inconsistent.
if (newCommitToken) {
this._updateCommitToken(newCommitToken);
}
Expand Down
9 changes: 9 additions & 0 deletions src/cloudflare/internal/test/d1/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ load("//:build/wd_test.bzl", "wd_test")
wd_test(
src = "d1-api-test.wd-test",
args = ["--experimental"],
data = glob(
["*.js"],
exclude = ["d1-api-test-with-sessions.js"],
),
)

wd_test(
src = "d1-api-test-with-sessions.wd-test",
args = ["--experimental"],
data = glob(["*.js"]),
)

Expand Down
Loading

0 comments on commit 4b1c31e

Please sign in to comment.