Skip to content

Commit 190f835

Browse files
committed
Add performance tests for get and set methods in kv module
- Introduced two new tests: testGetPerformance and testSetPerformance. - Each test measures the execution time of the respective method and asserts that it completes in under 100ms. - Ensured correct value retrieval and performance metrics are logged for both tests.
1 parent 41cb7a0 commit 190f835

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/puter-js/test/kv.test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,4 +503,46 @@ window.kvTests = [
503503
}
504504
}
505505
},
506+
{
507+
name: "testGetPerformance",
508+
description: "Test that get method takes less than 100ms",
509+
test: async function() {
510+
try {
511+
// Set up a key-value pair first
512+
await puter.kv.set('performanceTestKey', 'testValue');
513+
514+
// Measure the time it takes to get the value
515+
const startTime = performance.now();
516+
const value = await puter.kv.get('performanceTestKey');
517+
const endTime = performance.now();
518+
519+
const duration = endTime - startTime;
520+
521+
// Assert that the value is correct and timing is under 100ms
522+
assert(value === 'testValue', "Failed to retrieve correct value");
523+
assert(duration < 100, `Get method took ${duration}ms, which exceeds the 100ms limit`);
524+
525+
pass(`testGetPerformance passed: get took ${duration.toFixed(2)}ms`);
526+
} catch (error) {
527+
fail("testGetPerformance failed:", error);
528+
}
529+
}
530+
},
531+
{
532+
name: "testSetPerformance",
533+
description: "Test that set method takes less than 100ms",
534+
test: async function() {
535+
try {
536+
// Set up a key-value pair first
537+
const startTime = performance.now();
538+
await puter.kv.set('performanceTestKey', 'testValue');
539+
const endTime = performance.now();
540+
const duration = endTime - startTime;
541+
assert(duration < 100, `Set method took ${duration}ms, which exceeds the 100ms limit`);
542+
pass(`testSetPerformance passed: set took ${duration.toFixed(2)}ms`);
543+
} catch (error) {
544+
fail("testSetPerformance failed:", error);
545+
}
546+
}
547+
}
506548
]

0 commit comments

Comments
 (0)