Skip to content

Commit cf5ffe3

Browse files
committed
test: fix tests related to static fn and default models value
1 parent a00bbbc commit cf5ffe3

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

ResilientLLM.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ResilientLLM {
1515
anthropic: "claude-3-5-sonnet-20240620",
1616
openai: "gpt-4o-mini",
1717
gemini: "gemini-2.0-flash",
18-
ollama: "openai"
18+
ollama: "llama3.1:8b"
1919
}
2020

2121
constructor(options) {

test/README.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,27 @@ Unit tests for individual methods and components:
2424
- **Token Estimation**: Tests token counting functionality
2525
- **Constructor and Configuration**: Tests initialization and configuration options
2626

27+
### `resilient-llm.unit.test.js`
28+
Unit tests for the ResilientOperation integration:
29+
- **Async Function Execution**: Tests basic async function execution
30+
- **Parameter Passing**: Tests function execution with parameters
31+
- **Object Returns**: Tests functions returning objects
32+
- **Delay Handling**: Tests functions with time delays
33+
34+
### `resilient-operation.e2e.test.js`
35+
End-to-end tests for the ResilientOperation class:
36+
- **Basic Retry Logic**: Tests retry behavior for failed calls
37+
- **Circuit Breaker**: Tests circuit breaker functionality with failure thresholds
38+
- **Caching**: Tests result caching and duplicate call avoidance
39+
- **Preset Configurations**: Tests different preset configurations (fast, reliable)
40+
41+
### `test-runner.js`
42+
A simple test runner utility that:
43+
- Verifies test file existence
44+
- Checks Jest installation
45+
- Validates module imports
46+
- Provides test coverage summary
47+
2748
## Running Tests
2849

2950
### Prerequisites
@@ -91,6 +112,28 @@ The tests use Jest mocks for:
91112
- `setTimeout`/`setInterval` for time-based tests
92113
- Environment variables for configuration
93114

115+
## Known Issues and TODOs
116+
117+
### Memory Leak Investigation Needed
118+
The ResilientOperation class may have potential memory leaks due to ongoing async operations that continue after tests complete. This manifests as "Cannot log after tests are done" warnings.
119+
120+
**Current Issues:**
121+
- setTimeout calls in retry logic that aren't properly cleared
122+
- AbortController instances that aren't cleaned up
123+
- Rate limiting token bucket operations that continue running
124+
- Circuit breaker cooldown timers that persist
125+
126+
**Current Workaround:**
127+
- Tests add delays (`await new Promise(resolve => setTimeout(resolve, 200))`) to allow operations to complete
128+
- Console.log is mocked to prevent warnings
129+
130+
**TODO:**
131+
- Add a `destroy()` or `cleanup()` method to ResilientOperation
132+
- Ensure all timers are cleared when operations complete or fail
133+
- Add proper AbortController cleanup
134+
- Consider using WeakRef or FinalizationRegistry for automatic cleanup
135+
- Add memory leak detection in tests
136+
94137
## Adding New Tests
95138

96139
When adding new tests:
@@ -99,7 +142,8 @@ When adding new tests:
99142
3. Mock external dependencies appropriately
100143
4. Test both success and failure scenarios
101144
5. Include edge cases and error conditions
102-
6. Update this README if adding new test categories
145+
6. Add appropriate delays for async operations to complete
146+
7. Update this README if adding new test categories
103147

104148
## Test Configuration
105149

test/chat.unit.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ describe('ResilientLLM Chat Function Unit Tests', () => {
279279
describe('Token Estimation', () => {
280280
test('should estimate tokens for simple text', () => {
281281
const text = 'Hello, world!';
282-
const tokens = llm.estimateTokens(text);
282+
const tokens = ResilientLLM.estimateTokens(text);
283283
expect(tokens).toBeGreaterThan(0);
284284
expect(typeof tokens).toBe('number');
285285
});
@@ -288,20 +288,20 @@ describe('ResilientLLM Chat Function Unit Tests', () => {
288288
const shortText = 'Hello';
289289
const longText = 'Hello, this is a much longer text that should have more tokens than the short one.';
290290

291-
const shortTokens = llm.estimateTokens(shortText);
292-
const longTokens = llm.estimateTokens(longText);
291+
const shortTokens = ResilientLLM.estimateTokens(shortText);
292+
const longTokens = ResilientLLM.estimateTokens(longText);
293293

294294
expect(longTokens).toBeGreaterThan(shortTokens);
295295
});
296296

297297
test('should estimate tokens for empty text', () => {
298-
const tokens = llm.estimateTokens('');
298+
const tokens = ResilientLLM.estimateTokens('');
299299
expect(tokens).toBe(0);
300300
});
301301

302302
test('should estimate tokens for special characters', () => {
303303
const text = '你好世界 🌍 Special chars: !@#$%^&*()';
304-
const tokens = llm.estimateTokens(text);
304+
const tokens = ResilientLLM.estimateTokens(text);
305305
expect(tokens).toBeGreaterThan(0);
306306
});
307307
});

0 commit comments

Comments
 (0)