aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-09-06 08:13:11 +0200
committerChocobozzz <me@florianbigard.com>2021-09-06 08:13:11 +0200
commit70430c2796b6c0455a863edc62760a3d45951fc5 (patch)
tree7620d5a8db0c9b6cbf5a11d1c794875402828789
parent6d210220be0875d63461829d83c6e3a59d05cf7a (diff)
downloadPeerTube-70430c2796b6c0455a863edc62760a3d45951fc5.tar.gz
PeerTube-70430c2796b6c0455a863edc62760a3d45951fc5.tar.zst
PeerTube-70430c2796b6c0455a863edc62760a3d45951fc5.zip
Wait mock server termination
-rw-r--r--server/tests/api/object-storage/videos.ts6
-rw-r--r--server/tests/api/server/proxy.ts2
-rw-r--r--shared/extra-utils/mock-servers/mock-object-storage.ts3
-rw-r--r--shared/extra-utils/mock-servers/mock-plugin-blocklist.ts3
-rw-r--r--shared/extra-utils/mock-servers/mock-proxy.ts3
-rw-r--r--shared/extra-utils/mock-servers/utils.ts17
6 files changed, 27 insertions, 7 deletions
diff --git a/server/tests/api/object-storage/videos.ts b/server/tests/api/object-storage/videos.ts
index 6c9c224eb..6e6392181 100644
--- a/server/tests/api/object-storage/videos.ts
+++ b/server/tests/api/object-storage/videos.ts
@@ -243,7 +243,7 @@ function runTestSuite (options: {
243 }) 243 })
244 244
245 after(async function () { 245 after(async function () {
246 mockObjectStorage.terminate() 246 await mockObjectStorage.terminate()
247 247
248 await cleanupTests(servers) 248 await cleanupTests(servers)
249 }) 249 })
@@ -380,8 +380,8 @@ describe('Object storage for videos', function () {
380 playlistBucket: 'mybucket', 380 playlistBucket: 'mybucket',
381 webtorrentBucket: 'mybucket', 381 webtorrentBucket: 'mybucket',
382 382
383 playlistPrefix: 'streaming-playlists_', 383 playlistPrefix: 'streaming-playlists/',
384 webtorrentPrefix: 'webtorrent_', 384 webtorrentPrefix: 'webtorrent/',
385 385
386 useMockBaseUrl: true 386 useMockBaseUrl: true
387 }) 387 })
diff --git a/server/tests/api/server/proxy.ts b/server/tests/api/server/proxy.ts
index d5042ef27..72bd49078 100644
--- a/server/tests/api/server/proxy.ts
+++ b/server/tests/api/server/proxy.ts
@@ -65,7 +65,7 @@ describe('Test proxy', function () {
65 }) 65 })
66 66
67 after(async function () { 67 after(async function () {
68 proxy.terminate() 68 await proxy.terminate()
69 69
70 await cleanupTests(servers) 70 await cleanupTests(servers)
71 }) 71 })
diff --git a/shared/extra-utils/mock-servers/mock-object-storage.ts b/shared/extra-utils/mock-servers/mock-object-storage.ts
index f1c5a6123..b6071b2f2 100644
--- a/shared/extra-utils/mock-servers/mock-object-storage.ts
+++ b/shared/extra-utils/mock-servers/mock-object-storage.ts
@@ -4,6 +4,7 @@ import { Server } from 'http'
4import { pipeline } from 'stream' 4import { pipeline } from 'stream'
5import { randomInt } from '@shared/core-utils' 5import { randomInt } from '@shared/core-utils'
6import { ObjectStorageCommand } from '../server' 6import { ObjectStorageCommand } from '../server'
7import { terminateServer } from './utils'
7 8
8export class MockObjectStorage { 9export class MockObjectStorage {
9 private server: Server 10 private server: Server
@@ -37,6 +38,6 @@ export class MockObjectStorage {
37 } 38 }
38 39
39 terminate () { 40 terminate () {
40 if (this.server) this.server.close() 41 return terminateServer(this.server)
41 } 42 }
42} 43}
diff --git a/shared/extra-utils/mock-servers/mock-plugin-blocklist.ts b/shared/extra-utils/mock-servers/mock-plugin-blocklist.ts
index 6f66bf4f0..6a71532b5 100644
--- a/shared/extra-utils/mock-servers/mock-plugin-blocklist.ts
+++ b/shared/extra-utils/mock-servers/mock-plugin-blocklist.ts
@@ -1,6 +1,7 @@
1import express, { Request, Response } from 'express' 1import express, { Request, Response } from 'express'
2import { Server } from 'http' 2import { Server } from 'http'
3import { randomInt } from '@shared/core-utils' 3import { randomInt } from '@shared/core-utils'
4import { terminateServer } from './utils'
4 5
5type BlocklistResponse = { 6type BlocklistResponse = {
6 data: { 7 data: {
@@ -32,6 +33,6 @@ export class MockBlocklist {
32 } 33 }
33 34
34 terminate () { 35 terminate () {
35 if (this.server) this.server.close() 36 return terminateServer(this.server)
36 } 37 }
37} 38}
diff --git a/shared/extra-utils/mock-servers/mock-proxy.ts b/shared/extra-utils/mock-servers/mock-proxy.ts
index eb5f177c7..f955d3f9e 100644
--- a/shared/extra-utils/mock-servers/mock-proxy.ts
+++ b/shared/extra-utils/mock-servers/mock-proxy.ts
@@ -2,6 +2,7 @@
2import { createServer, Server } from 'http' 2import { createServer, Server } from 'http'
3import proxy from 'proxy' 3import proxy from 'proxy'
4import { randomInt } from '@shared/core-utils' 4import { randomInt } from '@shared/core-utils'
5import { terminateServer } from './utils'
5 6
6class MockProxy { 7class MockProxy {
7 private server: Server 8 private server: Server
@@ -16,7 +17,7 @@ class MockProxy {
16 } 17 }
17 18
18 terminate () { 19 terminate () {
19 if (this.server) this.server.close() 20 return terminateServer(this.server)
20 } 21 }
21} 22}
22 23
diff --git a/shared/extra-utils/mock-servers/utils.ts b/shared/extra-utils/mock-servers/utils.ts
new file mode 100644
index 000000000..64d94c868
--- /dev/null
+++ b/shared/extra-utils/mock-servers/utils.ts
@@ -0,0 +1,17 @@
1import { Server } from 'http'
2
3function terminateServer (server: Server) {
4 if (!server) return Promise.resolve()
5
6 return new Promise<void>((res, rej) => {
7 server.close(err => {
8 if (err) return rej(err)
9
10 return res()
11 })
12 })
13}
14
15export {
16 terminateServer
17}