|  | 
| 1 | 1 | import * as net from 'net'; | 
| 2 | 2 | import {Client, ConnectionConfig} from 'pg'; | 
| 3 | 3 | import {buildLogger, Logger} from '../lib/util'; | 
| 4 |  | -import {CLOSED_EVENT, ConnectionPool, PoolOptions} from '../lib/Pool'; | 
|  | 4 | +import {ConnectionPool, PoolOptions} from '../lib/Pool'; | 
| 5 | 5 | import {settings} from './settings'; | 
| 6 | 6 | 
 | 
| 7 |  | -export const PROXY_SERVER_PORT   = 3000; | 
| 8 | 7 | export const FAKE_PG_SERVER_PORT = 3001; | 
| 9 | 8 | 
 | 
| 10 | 9 | export function createNewPool(poolOptions: PoolOptions = {}, connectionOptions: ConnectionConfig = {}, logger?: Logger): ConnectionPool { | 
| @@ -56,41 +55,6 @@ export function removeAllClientAndShutdownPool(pool: ConnectionPool): Promise<vo | 
| 56 | 55 |     return shutdownPool(); | 
| 57 | 56 | } | 
| 58 | 57 | 
 | 
| 59 |  | -export function pgProxyServer(timeout: number, cb): net.Server { | 
| 60 |  | -    const server = net.createServer(proxySocket => { | 
| 61 |  | -        const pgSocket = new net.Socket(); | 
| 62 |  | - | 
| 63 |  | -        pgSocket.connect(settings.connection.port, settings.connection.host); | 
| 64 |  | - | 
| 65 |  | -        proxySocket.on('data', data => { | 
| 66 |  | -            setTimeout(() => { | 
| 67 |  | -                const flushed = pgSocket.write(data); | 
| 68 |  | - | 
| 69 |  | -                !flushed && proxySocket.pause(); | 
| 70 |  | -            }, timeout); | 
| 71 |  | -        }); | 
| 72 |  | - | 
| 73 |  | -        pgSocket.on('data', data => { | 
| 74 |  | -            const flushed = proxySocket.write(data); | 
| 75 |  | - | 
| 76 |  | -            !flushed && pgSocket.pause(); | 
| 77 |  | -        }); | 
| 78 |  | - | 
| 79 |  | -        proxySocket.on('drain', () => pgSocket.resume()); | 
| 80 |  | - | 
| 81 |  | -        pgSocket.on('drain', () => proxySocket.resume()); | 
| 82 |  | - | 
| 83 |  | -        proxySocket.on('close', () => pgSocket.end()); | 
| 84 |  | - | 
| 85 |  | -        pgSocket.on('close', () => proxySocket.end()); | 
| 86 |  | - | 
| 87 |  | -    }); | 
| 88 |  | - | 
| 89 |  | -    server.listen(PROXY_SERVER_PORT, cb); | 
| 90 |  | - | 
| 91 |  | -    return server; | 
| 92 |  | -} | 
| 93 |  | - | 
| 94 | 58 | export function fakePgServer(cb: Function): net.Server { | 
| 95 | 59 |     const server = net.createServer(); | 
| 96 | 60 | 
 | 
|  | 
0 commit comments