| 35 | } |
| 36 | |
| 37 | export async function test( |
| 38 | dbadapter: dbadapters.IDbAdapter, |
| 39 | timeoutMs: number = 10000 |
| 40 | ): Promise<ITestResult> { |
| 41 | let timer; |
| 42 | try { |
| 43 | const timeout = new Promise<TestResultStatus>( |
| 44 | resolve => (timer = setTimeout(() => resolve(TestResultStatus.TIMED_OUT), timeoutMs)) |
| 45 | ); |
| 46 | const executeQuery = dbadapter.execute("SELECT 1 AS x").then(() => TestResultStatus.SUCCESSFUL); |
| 47 | return { |
| 48 | status: await Promise.race([executeQuery, timeout]) |
| 49 | }; |
| 50 | } catch (e) { |
| 51 | return { |
| 52 | status: TestResultStatus.OTHER_ERROR, |
| 53 | error: e |
| 54 | }; |
| 55 | } finally { |
| 56 | if (timer) { |
| 57 | clearTimeout(timer); |
| 58 | } |
| 59 | } |
| 60 | } |