mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-02-25 18:55:32 -06:00
Wait mock server termination
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
17
shared/extra-utils/mock-servers/utils.ts
Normal file
17
shared/extra-utils/mock-servers/utils.ts
Normal file
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user