]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/extra-utils/server/server.ts
Add bin directory creation for parallel tests
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / server / server.ts
index bc5e1cd5fa12edb34424bba508f61927b1631f5d..31224ebe9f70f1a0b2149da9f5206addca049f83 100644 (file)
@@ -56,6 +56,7 @@ export class PeerTubeServer {
   port?: number
 
   rtmpPort?: number
+  rtmpsPort?: number
 
   parallel?: boolean
   internalServerNumber: number
@@ -154,6 +155,7 @@ export class PeerTubeServer {
 
     this.internalServerNumber = this.parallel ? this.randomServer() : this.serverNumber
     this.rtmpPort = this.parallel ? this.randomRTMP() : 1936
+    this.rtmpsPort = this.parallel ? this.randomRTMP() : 1937
     this.port = 9000 + this.internalServerNumber
 
     this.url = `http://localhost:${this.port}`
@@ -221,11 +223,17 @@ export class PeerTubeServer {
 
       this.app = fork(join(root(), 'dist', 'server.js'), options.peertubeArgs || [], forkOptions)
 
-      const onExit = function () {
-        return rej(new Error('Process exited'))
+      const onPeerTubeExit = () => rej(new Error('Process exited'))
+      const onParentExit = () => {
+        if (!this.app || !this.app.pid) return
+
+        try {
+          process.kill(self.app.pid)
+        } catch { /* empty */ }
       }
 
-      this.app.on('exit', onExit)
+      this.app.on('exit', onPeerTubeExit)
+      process.on('exit', onParentExit)
 
       this.app.stdout.on('data', function onStdout (data) {
         let dontContinue = false
@@ -254,16 +262,11 @@ export class PeerTubeServer {
         if (options.hideLogs === false) {
           console.log(data.toString())
         } else {
+          process.removeListener('exit', onParentExit)
           self.app.stdout.removeListener('data', onStdout)
-          self.app.removeListener('exit', onExit)
+          self.app.removeListener('exit', onPeerTubeExit)
         }
 
-        process.on('exit', () => {
-          try {
-            process.kill(self.app.pid)
-          } catch { /* empty */ }
-        })
-
         res()
       })
     })
@@ -319,6 +322,7 @@ export class PeerTubeServer {
       },
       storage: {
         tmp: `test${this.internalServerNumber}/tmp/`,
+        bin: `test${this.internalServerNumber}/bin/`,
         avatars: `test${this.internalServerNumber}/avatars/`,
         videos: `test${this.internalServerNumber}/videos/`,
         streaming_playlists: `test${this.internalServerNumber}/streaming-playlists/`,