-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-gate5-simple.ts
More file actions
77 lines (63 loc) · 2.17 KB
/
test-gate5-simple.ts
File metadata and controls
77 lines (63 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* Copyright (c) 2026 LinkedFlow Technologies
* Licensed under the Business Source License 1.1
* You may not use this file except in compliance with the License.
*/
import Redis from 'ioredis';
import { ConcurrencyGuard } from './src/services/ConcurrencyGuard';
import { logger } from './src/utils/logger';
/**
* Simple test to verify Gate 5 core components work
*/
async function testGate5Core() {
const redis = new Redis({
host: process.env.REDIS_HOST || 'localhost',
port: parseInt(process.env.REDIS_PORT || '6379'),
lazyConnect: true
});
try {
logger.info('Testing Gate 5 core components...');
// Test Redis connection
await redis.connect();
logger.info('✅ Redis connection successful');
// Test ConcurrencyGuard
const guard = new ConcurrencyGuard(redis);
const testAccountId = 'test-account-123';
// Test lock acquisition
const lockAcquired = await guard.acquireLock(testAccountId, 10000);
logger.info(`✅ Lock acquisition: ${lockAcquired}`);
if (lockAcquired) {
// Test lock info
const lockInfo = await guard.getLockInfo(testAccountId);
logger.info('✅ Lock info retrieved:', lockInfo);
// Test lock check
const isLocked = await guard.isLocked(testAccountId);
logger.info(`✅ Lock status check: ${isLocked}`);
// Test lock release
await guard.releaseLock(testAccountId);
logger.info('✅ Lock released successfully');
// Verify lock is gone
const isStillLocked = await guard.isLocked(testAccountId);
logger.info(`✅ Lock cleanup verified: ${!isStillLocked}`);
}
logger.info('🎉 Gate 5 core components test PASSED');
return true;
} catch (error) {
logger.error('❌ Gate 5 test failed:', { error: String(error) });
return false;
} finally {
await redis.quit();
}
}
// Run test if this file is executed directly
if (require.main === module) {
testGate5Core()
.then((passed) => {
logger.info(`Test result: ${passed ? 'PASSED' : 'FAILED'}`);
process.exit(passed ? 0 : 1);
})
.catch((error) => {
logger.error('Test execution error:', { error: String(error) });
process.exit(1);
});
}