| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | const { ipcRenderer } = require('electron'); | 
					
						
							|  |  |  | const fs = require('fs'); | 
					
						
							|  |  |  | const path = require('path'); | 
					
						
							| 
									
										
										
										
											2018-09-18 20:00:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  | const { expect } = require('chai'); | 
					
						
							| 
									
										
										
										
											2017-05-04 10:49:01 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-26 20:53:47 -04:00
										 |  |  | describe('process module', () => { | 
					
						
							| 
									
										
										
										
											2018-08-10 07:03:30 -07:00
										 |  |  |   describe('process.getCreationTime()', () => { | 
					
						
							|  |  |  |     it('returns a creation time', () => { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |       const creationTime = process.getCreationTime(); | 
					
						
							|  |  |  |       expect(creationTime).to.be.a('number').and.be.at.least(0); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-08-10 07:03:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-26 20:53:47 -04:00
										 |  |  |   describe('process.getCPUUsage()', () => { | 
					
						
							|  |  |  |     it('returns a cpu usage object', () => { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |       const cpuUsage = process.getCPUUsage(); | 
					
						
							|  |  |  |       expect(cpuUsage.percentCPUUsage).to.be.a('number'); | 
					
						
							|  |  |  |       expect(cpuUsage.idleWakeupsPerSecond).to.be.a('number'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2017-05-04 10:49:01 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-26 20:53:47 -04:00
										 |  |  |   describe('process.getIOCounters()', () => { | 
					
						
							| 
									
										
										
										
											2017-11-16 00:05:46 +03:00
										 |  |  |     before(function () { | 
					
						
							|  |  |  |       if (process.platform === 'darwin') { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |         this.skip(); | 
					
						
							| 
									
										
										
										
											2017-11-16 00:05:46 +03:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2017-10-26 20:53:47 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-16 00:05:46 +03:00
										 |  |  |     it('returns an io counters object', () => { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |       const ioCounters = process.getIOCounters(); | 
					
						
							|  |  |  |       expect(ioCounters.readOperationCount).to.be.a('number'); | 
					
						
							|  |  |  |       expect(ioCounters.writeOperationCount).to.be.a('number'); | 
					
						
							|  |  |  |       expect(ioCounters.otherOperationCount).to.be.a('number'); | 
					
						
							|  |  |  |       expect(ioCounters.readTransferCount).to.be.a('number'); | 
					
						
							|  |  |  |       expect(ioCounters.writeTransferCount).to.be.a('number'); | 
					
						
							|  |  |  |       expect(ioCounters.otherTransferCount).to.be.a('number'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-08-03 21:07:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-30 11:50:35 +02:00
										 |  |  |   describe('process.getBlinkMemoryInfo()', () => { | 
					
						
							|  |  |  |     it('returns blink memory information object', () => { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |       const heapStats = process.getBlinkMemoryInfo(); | 
					
						
							|  |  |  |       expect(heapStats.allocated).to.be.a('number'); | 
					
						
							|  |  |  |       expect(heapStats.total).to.be.a('number'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2019-05-30 11:50:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-28 00:57:53 -08:00
										 |  |  |   describe('process.getProcessMemoryInfo()', async () => { | 
					
						
							|  |  |  |     it('resolves promise successfully with valid data', async () => { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |       const memoryInfo = await process.getProcessMemoryInfo(); | 
					
						
							|  |  |  |       expect(memoryInfo).to.be.an('object'); | 
					
						
							| 
									
										
										
										
											2018-11-28 00:57:53 -08:00
										 |  |  |       if (process.platform === 'linux' || process.platform === 'windows') { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |         expect(memoryInfo.residentSet).to.be.a('number').greaterThan(0); | 
					
						
							| 
									
										
										
										
											2018-11-28 00:57:53 -08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |       expect(memoryInfo.private).to.be.a('number').greaterThan(0); | 
					
						
							| 
									
										
										
										
											2018-11-28 00:57:53 -08:00
										 |  |  |       // Shared bytes can be zero
 | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |       expect(memoryInfo.shared).to.be.a('number').greaterThan(-1); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-08-03 21:07:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe('process.getSystemMemoryInfo()', () => { | 
					
						
							|  |  |  |     it('returns system memory info object', () => { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |       const systemMemoryInfo = process.getSystemMemoryInfo(); | 
					
						
							|  |  |  |       expect(systemMemoryInfo.free).to.be.a('number'); | 
					
						
							|  |  |  |       expect(systemMemoryInfo.total).to.be.a('number'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-06-10 14:00:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 13:59:48 +01:00
										 |  |  |   describe('process.getSystemVersion()', () => { | 
					
						
							|  |  |  |     it('returns a string', () => { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |       expect(process.getSystemVersion()).to.be.a('string'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2019-02-18 13:59:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-10 14:00:36 +02:00
										 |  |  |   describe('process.getHeapStatistics()', () => { | 
					
						
							|  |  |  |     it('returns heap statistics object', () => { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |       const heapStats = process.getHeapStatistics(); | 
					
						
							|  |  |  |       expect(heapStats.totalHeapSize).to.be.a('number'); | 
					
						
							|  |  |  |       expect(heapStats.totalHeapSizeExecutable).to.be.a('number'); | 
					
						
							|  |  |  |       expect(heapStats.totalPhysicalSize).to.be.a('number'); | 
					
						
							|  |  |  |       expect(heapStats.totalAvailableSize).to.be.a('number'); | 
					
						
							|  |  |  |       expect(heapStats.usedHeapSize).to.be.a('number'); | 
					
						
							|  |  |  |       expect(heapStats.heapSizeLimit).to.be.a('number'); | 
					
						
							|  |  |  |       expect(heapStats.mallocedMemory).to.be.a('number'); | 
					
						
							|  |  |  |       expect(heapStats.peakMallocedMemory).to.be.a('number'); | 
					
						
							|  |  |  |       expect(heapStats.doesZapGarbage).to.be.a('boolean'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-09-18 20:00:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe('process.takeHeapSnapshot()', () => { | 
					
						
							| 
									
										
										
										
											2019-10-04 13:58:44 -07:00
										 |  |  |     it('returns true on success', async () => { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |       const filePath = path.join(await ipcRenderer.invoke('get-temp-dir'), 'test.heapsnapshot'); | 
					
						
							| 
									
										
										
										
											2018-09-18 20:00:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       const cleanup = () => { | 
					
						
							|  |  |  |         try { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |           fs.unlinkSync(filePath); | 
					
						
							| 
									
										
										
										
											2018-09-18 20:00:31 +02:00
										 |  |  |         } catch (e) { | 
					
						
							|  |  |  |           // ignore error
 | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |       }; | 
					
						
							| 
									
										
										
										
											2018-09-18 20:00:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       try { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |         const success = process.takeHeapSnapshot(filePath); | 
					
						
							|  |  |  |         expect(success).to.be.true(); | 
					
						
							|  |  |  |         const stats = fs.statSync(filePath); | 
					
						
							|  |  |  |         expect(stats.size).not.to.be.equal(0); | 
					
						
							| 
									
										
										
										
											2018-09-18 20:00:31 +02:00
										 |  |  |       } finally { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |         cleanup(); | 
					
						
							| 
									
										
										
										
											2018-09-18 20:00:31 +02:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-09-18 20:00:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('returns false on failure', () => { | 
					
						
							| 
									
										
										
										
											2020-03-20 13:28:31 -07:00
										 |  |  |       const success = process.takeHeapSnapshot(''); | 
					
						
							|  |  |  |       expect(success).to.be.false(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); |