-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
4,396 additions
and
711 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ on: | |
jobs: | ||
build: | ||
uses: nasa-gcn/.github/.github/workflows/node.yml@main | ||
with: | ||
test-options: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@app | ||
project | ||
|
||
@http | ||
get / | ||
|
||
@search | ||
sandboxEngine elasticsearch | ||
|
||
@plugins | ||
nasa-gcn/architect-plugin-search | ||
src ../../index.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { search } from '@nasa-gcn/architect-functions-search' | ||
import { ConnectionError } from '@opensearch-project/opensearch/lib/errors.js' | ||
|
||
export async function handler() { | ||
let statusCode = 200, | ||
result = {} | ||
|
||
const client = await search() | ||
try { | ||
result = await client.info() | ||
} catch (e) { | ||
if (e instanceof ConnectionError) { | ||
statusCode = 503 | ||
} else { | ||
throw e | ||
} | ||
} | ||
|
||
return { | ||
statusCode, | ||
body: JSON.stringify(result), | ||
headers: { | ||
'cache-control': | ||
'no-cache, no-store, must-revalidate, max-age=0, s-maxage=0', | ||
'content-type': 'application/json; charset=utf8', | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@app | ||
project | ||
|
||
@http | ||
get / | ||
|
||
@search | ||
sandboxEngine opensearch | ||
|
||
@plugins | ||
nasa-gcn/architect-plugin-search | ||
src ../../index.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../elasticsearch/src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import assert from 'node:assert' | ||
import { dirname, join } from 'node:path' | ||
import { afterEach, beforeEach, describe, test } from 'node:test' | ||
import { fileURLToPath } from 'node:url' | ||
import { spawn, untilTerminated } from '../processes' | ||
import { ChildProcess } from 'node:child_process' | ||
|
||
async function sleep(timeout: number) { | ||
return new Promise((resolve) => setTimeout(resolve, timeout)) | ||
} | ||
|
||
async function fetchRetry( | ||
...props: Parameters<typeof fetch> | ||
): ReturnType<typeof fetch> { | ||
let response | ||
try { | ||
response = await fetch(...props) | ||
} catch (e) { | ||
if (!(e instanceof TypeError)) throw e | ||
} | ||
|
||
if (response?.ok) { | ||
return response | ||
} else { | ||
await sleep(1000) | ||
return await fetchRetry(...props) | ||
} | ||
} | ||
|
||
const signals = ['SIGTERM'] as const | ||
const engines = ['elasticsearch', 'opensearch'] | ||
|
||
engines.forEach((engine) => | ||
signals.forEach((signal) => { | ||
describe(`${engine} stops when sent signal ${signal}`, () => { | ||
let process: ChildProcess | ||
|
||
beforeEach(async () => { | ||
// FIXME: replace with import.meta.resolve once it is stable in Node.js | ||
const cwd = join(dirname(fileURLToPath(import.meta.url)), engine) | ||
|
||
process = await spawn('npx', ['arc', 'sandbox'], { | ||
cwd, | ||
stdio: 'inherit', | ||
}) | ||
}) | ||
|
||
afterEach(async () => { | ||
const processIsDead = untilTerminated(process) | ||
|
||
assert.ok(process.kill(signal)) | ||
// Make sure arc sandbox is dead | ||
await processIsDead | ||
// Give subprocesses some time to die | ||
await sleep(1000) | ||
|
||
// Make sure that arc sandbox and opensearch/elasticseasrch are both | ||
// down and not responding to HTTP requests any more | ||
for (const port of [3333, 9200]) { | ||
assert.rejects( | ||
fetch(`http://localhost:${port}/`), | ||
TypeError, | ||
'fetch failed' | ||
) | ||
} | ||
}) | ||
|
||
test('connection was alive', async () => { | ||
const response = await fetchRetry('http://localhost:3333/') | ||
const result = await response.json() | ||
assert.deepStrictEqual(result?.meta.connection.status, 'alive') | ||
}) | ||
}) | ||
}) | ||
) |
Oops, something went wrong.