gitoriaLog in with ident

mpackdb

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitc4cdb9b6c4cdb9b6node: import prefixes (Deno compat) + pre-existing index-state WIPcaramboleyoc4cdb9b6/tests/lockfile.test.js

1.3 KB

  1. import MPackDB from '../src/MPackDB.js';
  2. import { rm } from 'fs/promises';
  3. const TEST_DB_PATH = 'db/lockfile';
  4. console.log('--- Lockfile Test ---');
  5. // Clean up
  6. await rm(TEST_DB_PATH, { recursive: true, force: true });
  7. const db = new MPackDB(`${TEST_DB_PATH}/db`);
  8. // Test 1: Insert
  9. console.log('Test 1: Insert with lock');
  10. const id1 = await db.insert({ name: 'Alice', age: 30 });
  11. console.log('✓ Inserted:', id1);
  12. // Test 2: Multiple inserts
  13. console.log('\nTest 2: Multiple inserts');
  14. const id2 = await db.insert({ name: 'Bob', age: 25 });
  15. const id3 = await db.insert({ name: 'Charlie', age: 35 });
  16. console.log('✓ Inserted:', id2, id3);
  17. // Test 3: Read (no lock needed)
  18. console.log('\nTest 3: Read all');
  19. const all = await db.find();
  20. console.log('✓ Found', all.length, 'records');
  21. // Test 4: Delete with lock
  22. console.log('\nTest 4: Delete with lock');
  23. await db.delete(u => u.age === 25);
  24. const remaining = await db.find();
  25. console.log('✓ Remaining:', remaining.length, 'records');
  26. // Test 5: Verify no stale lock
  27. console.log('\nTest 5: Verify lock cleanup');
  28. const { readdirSync } = await import('fs');
  29. const files = readdirSync(TEST_DB_PATH);
  30. const hasLock = files.some(f => f.endsWith('.lock'));
  31. if (hasLock) {
  32. throw new Error('❌ Lock file not cleaned up!');
  33. }
  34. console.log('✓ No stale lock files');
  35. console.log('\n✓ All tests passed!');

Branches

Latest commits

  • c4cdb9b6node: import prefixes (Deno compat) + pre-existing index-state WIPcaramboleyo
  • 0afb8f4bupdate now must be a callbackcaramboleyo
  • cde73eb4release 1.0.6caramboleyo
  • d01dda02add index hints, intersection, boundingBox; remove findByIndexcaramboleyo
  • b8ffc1a0release 1.0.5caramboleyo
  • d47876a1reimplemented lost features like indexed find and more testscaramboleyo
  • 7f08da9afixed insert ignoring model definitioncaramboleyo
  • 705774a9added flush before findcaramboleyo
  • b4db6391initial commitcaramboleyo