Skip to content

Commit 1c36331

Browse files
committed
worker write tests
1 parent ca1dbed commit 1c36331

3 files changed

Lines changed: 30 additions & 9 deletions

File tree

test/test.browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ describe('Browser main tests', function () {
3939
writeSuccess = true;
4040
}
4141
});
42-
waitForTrue(()=>{return writeSuccess;},1);
42+
await waitForTrue(()=>{return writeSuccess;},1);
4343
});
4444
});

test/test.worker.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,17 @@ describe('web worker tests', function () {
5858
expect(status).to.be.true;
5959
});
6060

61-
it('Should phoenix native read write in worker', async function () {
61+
it('Should phoenix native write in worker', async function () {
6262
messageFromWorker = null;
63-
worker.postMessage('RWMountCheck');
64-
let status = await waitForWorkerMessage('RWMountCheck.ok', 1000);
63+
worker.postMessage('writeMountCheck');
64+
let status = await waitForWorkerMessage('writeMountCheck.ok', 1000);
65+
expect(status).to.be.true;
66+
});
67+
68+
it('Should phoenix native read in worker', async function () {
69+
messageFromWorker = null;
70+
worker.postMessage('readMountCheck');
71+
let status = await waitForWorkerMessage('readMountCheck.ok', 1000);
6572
expect(status).to.be.true;
6673
});
6774
});

test/worker-task.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,36 @@ function phoenixFsCheck() {
1616
}
1717
}
1818

19-
function checkReadWriteInMountPath() {
20-
fs.writeFile(`${mountTestPath}/a.txt`, 'hello World', 'utf8', (err)=>{
19+
function checkWriteInMountPath() {
20+
console.log('worker: checkWriteInMountPath');
21+
fs.writeFile(`${mountTestPath}/workerWrite.txt`, 'hello World', 'utf8', (err)=>{
2122
if(!err){
22-
postMessage('RWMountCheck.ok');
23+
postMessage('writeMountCheck.ok');
2324
return;
2425
}
2526
console.log(err);
2627
});
2728
}
2829

30+
function checkReadInMountPath() {
31+
console.log('worker: checkReadInMountPath');
32+
fs.readFile(`${mountTestPath}/workerWrite.txt`, (err, content)=>{
33+
if(!err && content === 'hello World'){
34+
postMessage('readMountCheck.ok');
35+
return;
36+
}
37+
console.log('file read:', err, content);
38+
});
39+
}
40+
2941
self.addEventListener('message', (event) => {
30-
console.log('Worker:', event);
42+
console.log('Worker received: ', event);
3143
let command = event.data;
3244
switch (command) {
3345
case 'fsCheck': fsCheck(); break;
3446
case 'phoenixFsCheck': phoenixFsCheck(); break;
35-
case 'RWMountCheck': checkReadWriteInMountPath(); break;
47+
case 'writeMountCheck': checkWriteInMountPath(); break;
48+
case 'readMountCheck': checkReadInMountPath(); break;
49+
default: console.error('unknown worker command: ', command);
3650
}
3751
}, false);

0 commit comments

Comments
 (0)