Skip to content

Commit 5f6967e

Browse files
committed
fix share workers
1 parent 5c14df4 commit 5f6967e

File tree

4 files changed

+160
-0
lines changed

4 files changed

+160
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Test Suite for Issue #5066 Fix
2+
3+
This directory contains tests that validate the fix for **Issue #5066: Unable to inject data between workers because of proxy object**.
4+
5+
## Test Files
6+
7+
### `proxy_test.js`
8+
Basic tests that verify the core functionality of `share()` and `inject()` functions:
9+
- Basic data sharing with primitive types (strings, numbers)
10+
- Complex nested data structures (objects, arrays)
11+
- Property access patterns that should work after the fix
12+
13+
### `final_test.js`
14+
Comprehensive end-to-end validation test that covers:
15+
- Multiple data types and structures
16+
- Data overriding scenarios
17+
- Deep nested property access
18+
- Key enumeration functionality
19+
- Real-world usage patterns
20+
21+
## Running the Tests
22+
23+
### Single-threaded execution:
24+
```bash
25+
npx codeceptjs run proxy_test.js
26+
npx codeceptjs run final_test.js
27+
```
28+
29+
### Multi-worker execution (tests worker communication):
30+
```bash
31+
npx codeceptjs run-workers 2 proxy_test.js
32+
npx codeceptjs run-workers 2 final_test.js
33+
```
34+
35+
## What the Fix Addresses
36+
37+
1. **Circular Dependency Error**: Fixed "Support object undefined is not defined" error in `workerStorage.js`
38+
2. **Proxy System Enhancement**: Updated container proxy system to handle dynamically shared data
39+
3. **Worker Communication**: Ensured data sharing works correctly between worker threads
40+
4. **Key Enumeration**: Made sure `Object.keys(inject())` shows shared properties
41+
42+
## Expected Results
43+
44+
All tests should pass in both single-threaded and multi-worker modes, demonstrating that:
45+
- `share({ data })` correctly shares data between workers
46+
- `inject()` returns a proxy object with proper access to shared data
47+
- Both direct property access and nested object traversal work correctly
48+
- Key enumeration shows all shared properties
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
exports.config = {
2+
tests: './proxy_test.js',
3+
output: './output',
4+
helpers: {
5+
FileSystem: {}
6+
},
7+
include: {},
8+
mocha: {},
9+
name: 'workers-proxy-issue',
10+
};
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
const assert = require('assert');
2+
3+
Feature('Complete validation for issue #5066 fix');
4+
5+
Scenario('End-to-end worker data sharing validation', () => {
6+
console.log('=== Testing complete data sharing workflow ===');
7+
8+
// Test 1: Basic data sharing
9+
share({
10+
message: 'Hello from main thread',
11+
config: { timeout: 5000, retries: 3 },
12+
users: ['alice', 'bob', 'charlie']
13+
});
14+
15+
const data = inject();
16+
17+
// Verify all property types work correctly
18+
assert.strictEqual(data.message, 'Hello from main thread', 'String property should work');
19+
assert.strictEqual(data.config.timeout, 5000, 'Nested object property should work');
20+
assert.strictEqual(data.config.retries, 3, 'Nested object property should work');
21+
assert(Array.isArray(data.users), 'Array property should work');
22+
assert.strictEqual(data.users.length, 3, 'Array length should work');
23+
assert.strictEqual(data.users[0], 'alice', 'Array access should work');
24+
25+
// Test 2: Data overriding
26+
share({ message: 'Updated message' });
27+
const updatedData = inject();
28+
assert.strictEqual(updatedData.message, 'Updated message', 'Data override should work');
29+
assert.strictEqual(updatedData.config.timeout, 5000, 'Previous data should persist');
30+
31+
// Test 3: Complex nested structures
32+
share({
33+
testSuite: {
34+
name: 'E2E Tests',
35+
tests: [
36+
{ name: 'Login test', status: 'passed', data: { user: 'admin', pass: 'secret' } },
37+
{ name: 'Checkout test', status: 'failed', error: 'Timeout occurred' }
38+
],
39+
metadata: {
40+
browser: 'chrome',
41+
version: '91.0',
42+
viewport: { width: 1920, height: 1080 }
43+
}
44+
}
45+
});
46+
47+
const complexData = inject();
48+
assert.strictEqual(complexData.testSuite.name, 'E2E Tests', 'Deep nested string should work');
49+
assert.strictEqual(complexData.testSuite.tests[0].data.user, 'admin', 'Very deep nested access should work');
50+
assert.strictEqual(complexData.testSuite.metadata.viewport.width, 1920, 'Very deep nested number should work');
51+
52+
// Test 4: Key enumeration
53+
const allKeys = Object.keys(inject());
54+
assert(allKeys.includes('message'), 'Keys should include shared properties');
55+
assert(allKeys.includes('testSuite'), 'Keys should include all shared properties');
56+
57+
console.log('✅ ALL TESTS PASSED - Issue #5066 is completely fixed!');
58+
console.log('✅ Workers can now share and inject data without circular dependency errors');
59+
console.log('✅ Proxy objects work correctly for both direct and nested property access');
60+
});
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const assert = require('assert');
2+
3+
Feature('Fix for issue #5066: Unable to inject data between workers because of proxy object');
4+
5+
Scenario('Basic share and inject functionality', () => {
6+
console.log('Testing basic share() and inject() functionality...');
7+
8+
// This is the basic pattern that should work after the fix
9+
const originalData = { message: 'Hello', count: 42 };
10+
share(originalData);
11+
12+
const injectedData = inject();
13+
console.log('Shared data keys:', Object.keys(originalData));
14+
console.log('Injected data keys:', Object.keys(injectedData));
15+
16+
// These assertions should pass after the fix
17+
assert.strictEqual(injectedData.message, 'Hello', 'String property should be accessible');
18+
assert.strictEqual(injectedData.count, 42, 'Number property should be accessible');
19+
20+
console.log('✅ SUCCESS: Basic share/inject works!');
21+
});
22+
23+
Scenario('Complex nested data structures', () => {
24+
console.log('Testing complex nested data sharing...');
25+
26+
const testDataJson = {
27+
users: [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }],
28+
settings: { theme: 'dark', language: 'en' }
29+
};
30+
31+
share({ testDataJson });
32+
33+
const data = inject();
34+
35+
// These should work after the fix
36+
assert(data.testDataJson, 'testDataJson should be accessible');
37+
assert(Array.isArray(data.testDataJson.users), 'users should be an array');
38+
assert.strictEqual(data.testDataJson.users[0].name, 'John', 'Should access nested user data');
39+
assert.strictEqual(data.testDataJson.settings.theme, 'dark', 'Should access nested settings');
40+
41+
console.log('✅ SUCCESS: Complex nested data works!');
42+
});

0 commit comments

Comments
 (0)