Versions 213 to 318
Lines 105–165 at 318 (were 105–107 at 213)
105105 assert.equal(cache.retainedBytes, 0); 106106 source.db.close(); 109+test("a rollback drops only what its transaction wrote; a nested commit's writes go with an outer rollback (abso Capacity)", () => { 110+ const source = new SqlState(); 112+ const cache = new CachedStateStorage(source, 8192, 16); 113+ source.write("rows", "kept", "k"); 114+ source.write("rows", "inner", "i0"); 115+ source.write("rows", "outer", "o0"); 116+ for (const key of ["kept", "inner", "outer"]) cache.read("rows", key); 117+ const reads = source.reads; 118+ // A projection scratch scope: rolled back on purpose, and the rows read around it stay cached. 121+ cache.transaction(() => { 122+ cache.write("scratch", "x", "temporary"); 123+ throw new Error("scratch rollback"); 127+ assert.equal(cache.read("rows", "kept"), "k"); 128+ assert.equal(source.reads, reads, "the rows read before were not read again"); 129+ assert.equal(cache.read("scratch", "x"), undefined); 130+ // A nested transaction commits, then the outer one rolls back: both writes are undone, and the cache forgets both. 133+ cache.transaction(() => { 134+ cache.write("rows", "outer", "o1"); 135+ cache.transaction(() => cache.write("rows", "inner", "i1")); 136+ assert.equal(cache.read("rows", "inner"), "i1"); 137+ throw new Error("outer rollback"); 141+ assert.equal(cache.read("rows", "inner"), "i0"); 142+ assert.equal(cache.read("rows", "outer"), "o0"); 143+ assert.equal(cache.read("rows", "kept"), "k"); 149+test("a row over the per-row limit is read but not kept, and pushes nothing out (abso Capacity)", () => { 150+ const source = new SqlState(); 152+ const cache = new CachedStateStorage(source, 8192, 64, 1024); 153+ source.write("rows", "small", "s"); 154+ source.write("rows", "big", "x".repeat(2000)); 155+ cache.read("rows", "small"); 156+ const reads = source.reads; 157+ assert.equal((cache.read("rows", "big") as string).length, 2000); 158+ assert.equal(cache.read("rows", "small"), "s"); 159+ assert.equal(source.reads, reads + 1, "the big row was read from storage once and the small one stayed cached"); 160+ assert.equal((cache.read("rows", "big") as string).length, 2000); 161+ assert.equal(source.reads, reads + 2, "the big row isn't kept");