]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Wait mock server termination
authorChocobozzz <me@florianbigard.com>
Mon, 6 Sep 2021 06:13:11 +0000 (08:13 +0200)
committerChocobozzz <me@florianbigard.com>
Mon, 6 Sep 2021 06:13:11 +0000 (08:13 +0200)
server/tests/api/object-storage/videos.ts
server/tests/api/server/proxy.ts
shared/extra-utils/mock-servers/mock-object-storage.ts
shared/extra-utils/mock-servers/mock-plugin-blocklist.ts
shared/extra-utils/mock-servers/mock-proxy.ts
shared/extra-utils/mock-servers/utils.ts [new file with mode: 0644]

index 6c9c224eb365f2b11aeaa50dc593c06f354327ad..6e639218169b57988ef83d925bcd9b4828b6c94e 100644 (file)
@@ -243,7 +243,7 @@ function runTestSuite (options: {
   })
 
   after(async function () {
-    mockObjectStorage.terminate()
+    await mockObjectStorage.terminate()
 
     await cleanupTests(servers)
   })
@@ -380,8 +380,8 @@ describe('Object storage for videos', function () {
       playlistBucket: 'mybucket',
       webtorrentBucket: 'mybucket',
 
-      playlistPrefix: 'streaming-playlists_',
-      webtorrentPrefix: 'webtorrent_',
+      playlistPrefix: 'streaming-playlists/',
+      webtorrentPrefix: 'webtorrent/',
 
       useMockBaseUrl: true
     })
index d5042ef27bd656abf8efc6824364b1b200a63e99..72bd49078dd6ba27e8c5292a6beb75910fbb54ee 100644 (file)
@@ -65,7 +65,7 @@ describe('Test proxy', function () {
   })
 
   after(async function () {
-    proxy.terminate()
+    await proxy.terminate()
 
     await cleanupTests(servers)
   })
index f1c5a612388136a4fdce3f06028a7b1bb2d703ef..b6071b2f2977364d42b3ee153a6a7ecb96a46d48 100644 (file)
@@ -4,6 +4,7 @@ import { Server } from 'http'
 import { pipeline } from 'stream'
 import { randomInt } from '@shared/core-utils'
 import { ObjectStorageCommand } from '../server'
+import { terminateServer } from './utils'
 
 export class MockObjectStorage {
   private server: Server
@@ -37,6 +38,6 @@ export class MockObjectStorage {
   }
 
   terminate () {
-    if (this.server) this.server.close()
+    return terminateServer(this.server)
   }
 }
index 6f66bf4f0e4b363325d95c7c24e933ed2e78f428..6a71532b589d7cce070bc202eb2488e59228a5e8 100644 (file)
@@ -1,6 +1,7 @@
 import express, { Request, Response } from 'express'
 import { Server } from 'http'
 import { randomInt } from '@shared/core-utils'
+import { terminateServer } from './utils'
 
 type BlocklistResponse = {
   data: {
@@ -32,6 +33,6 @@ export class MockBlocklist {
   }
 
   terminate () {
-    if (this.server) this.server.close()
+    return terminateServer(this.server)
   }
 }
index eb5f177c71d525dd32a1f60b168610b145f74ed6..f955d3f9eff2aa8b830386f81de03ea3309bc148 100644 (file)
@@ -2,6 +2,7 @@
 import { createServer, Server } from 'http'
 import proxy from 'proxy'
 import { randomInt } from '@shared/core-utils'
+import { terminateServer } from './utils'
 
 class MockProxy {
   private server: Server
@@ -16,7 +17,7 @@ class MockProxy {
   }
 
   terminate () {
-    if (this.server) this.server.close()
+    return terminateServer(this.server)
   }
 }
 
diff --git a/shared/extra-utils/mock-servers/utils.ts b/shared/extra-utils/mock-servers/utils.ts
new file mode 100644 (file)
index 0000000..64d94c8
--- /dev/null
@@ -0,0 +1,17 @@
+import { Server } from 'http'
+
+function terminateServer (server: Server) {
+  if (!server) return Promise.resolve()
+
+  return new Promise<void>((res, rej) => {
+    server.close(err => {
+      if (err) return rej(err)
+
+      return res()
+    })
+  })
+}
+
+export {
+  terminateServer
+}