GeezerVison is showing github.com — Multiple fixes for SQLiteStore, enable them in CI (#3881) · nodejs/undici@55ad16f
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .github/workflows/nodejs.yml +25-4Lines changed: 25 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -37,13 +37,13 @@ jobs: | 37 | 37 | - name: Checkout | 38 | 38 | uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 | 39 | 39 | with: | 40 | | - persist-credentials: false | | 40 | + persist-credentials: false | 41 | 41 |
| 42 | 42 | - name: Setup Node.js | 43 | 43 | uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 | 44 | 44 | with: | 45 | 45 | node-version: lts/* | 46 | | - | | 46 | + | 47 | 47 | - name: Install dependencies | 48 | 48 | run: npm install | 49 | 49 |
| @@ -170,19 +170,40 @@ jobs: | 170 | 170 | - name: Checkout | 171 | 171 | uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 | 172 | 172 | with: | 173 | | - persist-credentials: false | | 173 | + persist-credentials: false | 174 | 174 |
| 175 | 175 | - name: Setup Node.js | 176 | 176 | uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 | 177 | 177 | with: | 178 | 178 | node-version: lts/* | 179 | | - | | 179 | + | 180 | 180 | - name: Install dependencies | 181 | 181 | run: npm install | 182 | 182 |
| 183 | 183 | - name: Run typings tests | 184 | 184 | run: npm run test:typescript | 185 | 185 |
| | 186 | + test-sqlite: | | 187 | + name: Test with SQLite enabled | | 188 | + timeout-minutes: 15 | | 189 | + runs-on: ubuntu-latest | | 190 | + steps: | | 191 | + - name: Checkout | | 192 | + uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 | | 193 | + with: | | 194 | + persist-credentials: false | | 195 | + | | 196 | + - name: Setup Node.js | | 197 | + uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 | | 198 | + with: | | 199 | + node-version: 22 | | 200 | + | | 201 | + - name: Install dependencies | | 202 | + run: npm install | | 203 | + | | 204 | + - name: Run typings tests | | 205 | + run: npm run test:sqlite | | 206 | + | 186 | 207 | automerge: | 187 | 208 | if: > | 188 | 209 | github.event_name == 'pull_request' && github.event.pull_request.user.login == 'dependabot[bot]' | |
Collapse file Copy file name to clipboardExpand all lines: lib/cache/sqlite-cache-store.js +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -274,7 +274,7 @@ class SqliteCacheStore { | 274 | 274 | value.statusCode, | 275 | 275 | value.statusMessage, | 276 | 276 | value.headers ? JSON.stringify(value.headers) : null, | 277 | | - value.etag, | | 277 | + value.etag ? value.etag : null, | 278 | 278 | value.cachedAt, | 279 | 279 | value.staleAt, | 280 | 280 | value.deleteAt, | @@ -316,7 +316,7 @@ class SqliteCacheStore { | 316 | 316 | } | 317 | 317 |
| 318 | 318 | #prune () { | 319 | | - if (this.#size <= this.#maxCount) { | | 319 | + if (this.size <= this.#maxCount) { | 320 | 320 | return 0 | 321 | 321 | } | 322 | 322 |
| @@ -341,7 +341,7 @@ class SqliteCacheStore { | 341 | 341 | * Counts the number of rows in the cache | 342 | 342 | * @returns {Number} | 343 | 343 | */ | 344 | | - get #size () { | | 344 | + get size () { | 345 | 345 | const { total } = this.#countEntriesQuery.get() | 346 | 346 | return total | 347 | 347 | } | @@ -388,7 +388,7 @@ class SqliteCacheStore { | 388 | 388 | const vary = JSON.parse(value.vary) | 389 | 389 |
| 390 | 390 | for (const header in vary) { | 391 | | - if (headerValueEquals(headers[header], vary[header])) { | | 391 | + if (!headerValueEquals(headers[header], vary[header])) { | 392 | 392 | matches = false | 393 | 393 | break | 394 | 394 | } | |
Collapse file Copy file name to clipboardExpand all lines: package.json +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 73 | 73 | "test:javascript:without-intl": "npm run test:javascript:no-jest", | 74 | 74 | "test:busboy": "borp -p \"test/busboy/*.js\"", | 75 | 75 | "test:cache": "borp -p \"test/cache/*.js\"", | | 76 | + "test:sqlite": "NODE_OPTIONS=--experimental-sqlite borp -p \"test/cache-interceptor/*.js\"", | 76 | 77 | "test:cache-interceptor": "borp -p \"test/cache-interceptor/*.js\"", | 77 | 78 | "test:cookies": "borp -p \"test/cookie/*.js\"", | 78 | 79 | "test:eventsource": "npm run build:node && borp --expose-gc -p \"test/eventsource/*.js\"", | |
Collapse file Copy file name to clipboardExpand all lines: test/cache-interceptor/sqlite-cache-store-tests.js +48-2Lines changed: 48 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -52,7 +52,7 @@ test('SqliteCacheStore works nicely with multiple stores', async (t) => { | 52 | 52 | const requestValue = { | 53 | 53 | statusCode: 200, | 54 | 54 | statusMessage: '', | 55 | | - rawHeaders: [Buffer.from('1'), Buffer.from('2'), Buffer.from('3')], | | 55 | + headers: { foo: 'bar' }, | 56 | 56 | cachedAt: Date.now(), | 57 | 57 | staleAt: Date.now() + 10000, | 58 | 58 | deleteAt: Date.now() + 20000 | @@ -111,7 +111,7 @@ test('SqliteCacheStore maxEntries', async (t) => { | 111 | 111 | const requestValue = { | 112 | 112 | statusCode: 200, | 113 | 113 | statusMessage: '', | 114 | | - rawHeaders: [Buffer.from('1'), Buffer.from('2'), Buffer.from('3')], | | 114 | + headers: { foo: 'bar' }, | 115 | 115 | cachedAt: Date.now(), | 116 | 116 | staleAt: Date.now() + 10000, | 117 | 117 | deleteAt: Date.now() + 20000 | @@ -125,3 +125,49 @@ test('SqliteCacheStore maxEntries', async (t) => { | 125 | 125 |
| 126 | 126 | strictEqual(store.size <= 11, true) | 127 | 127 | }) | | 128 | + | | 129 | +test('two writes', async (t) => { | | 130 | + if (!hasSqlite) { | | 131 | + t.skip() | | 132 | + return | | 133 | + } | | 134 | + | | 135 | + const SqliteCacheStore = require('../../lib/cache/sqlite-cache-store.js') | | 136 | + const sqliteLocation = 'cache-interceptor.sqlite' | | 137 | + | | 138 | + const store = new SqliteCacheStore({ | | 139 | + location: sqliteLocation, | | 140 | + maxCount: 10 | | 141 | + }) | | 142 | + | | 143 | + t.after(async () => { | | 144 | + await rm(sqliteLocation) | | 145 | + }) | | 146 | + | | 147 | + const request = { | | 148 | + origin: 'localhost', | | 149 | + path: '/', | | 150 | + method: 'GET', | | 151 | + headers: {} | | 152 | + } | | 153 | + | | 154 | + const requestValue = { | | 155 | + statusCode: 200, | | 156 | + statusMessage: '', | | 157 | + headers: { foo: 'bar' }, | | 158 | + cachedAt: Date.now(), | | 159 | + staleAt: Date.now() + 10000, | | 160 | + deleteAt: Date.now() + 20000 | | 161 | + } | | 162 | + const requestBody = ['asd', '123'] | | 163 | + | | 164 | + { | | 165 | + const writable = store.createWriteStream(request, requestValue) | | 166 | + await once(writeResponse(writable, requestBody), 'close') | | 167 | + } | | 168 | + | | 169 | + { | | 170 | + const writable = store.createWriteStream(request, requestValue) | | 171 | + await once(writeResponse(writable, requestBody), 'close') | | 172 | + } | | 173 | +}) |
|