finished actions => handlers refacto, small bux fix in maestro => Test maestro1 OK
This commit is contained in:
+10
-3
@@ -1,4 +1,11 @@
|
||||
clear; node test.js --guiDatabase test_p42GUI --simDatabase test_p42SIM maestro1 --userUuid a4f33373-6adf-4d2d-9a6d-7fa0abf8b01f --simulationUuid 0x019ec742e12175c685a97bf9300b6b49
|
||||
|
||||
|
||||
# Test DBs: point all gods at the same config (or edit config.json mysql section).
|
||||
# Example:
|
||||
# ./startAllGods.sh --config /opt/p42GodDaemons/config.json
|
||||
# ./Maestro/startMaestro.sh /opt/p42GodDaemons/config.json
|
||||
|
||||
clear; node test.js maestro1 \
|
||||
--config ../config.json \
|
||||
--guiDatabase test_p42GUI --simDatabase test_p42SIM \
|
||||
--fakeAgentsReady --fakeGpsReady \
|
||||
--userUuid a4f33373-6adf-4d2d-9a6d-7fa0abf8b01f \
|
||||
--simulationUuid 0x019ec742e12175c685a97bf9300b6b49
|
||||
|
||||
+79
-12
@@ -64,6 +64,54 @@ async function findSimulationFixture(ctx) {
|
||||
})
|
||||
}
|
||||
|
||||
function godsReadyChannel(config) {
|
||||
return(config.maestro?.lifecycle?.godsReadyChannel
|
||||
?? config.gps?.lifecycle?.godsReadyChannel
|
||||
?? 'arena:gods:ready')
|
||||
}
|
||||
|
||||
async function publishFakeReadyToStart(ctx, { sender, simulationId, agentIds }) {
|
||||
const { arenaCnx } = ctx
|
||||
const payload = {
|
||||
success: true,
|
||||
simulationId,
|
||||
err: null,
|
||||
}
|
||||
if(agentIds) payload.agentIds = agentIds
|
||||
|
||||
await arenaCnx.redisPublish(godsReadyChannel(ctx.config), {
|
||||
eventType: 'readyToStart',
|
||||
sender,
|
||||
payload,
|
||||
})
|
||||
}
|
||||
|
||||
async function publishFakeReadies(ctx, simulationId, agentIds) {
|
||||
const { argv, config, log } = ctx
|
||||
|
||||
if(argv.fakeGpsReady) {
|
||||
const senderId = config.gps?.senderId ?? 'gps'
|
||||
log('action', `Faking GPS readyToStart (sender=${senderId})...`)
|
||||
await publishFakeReadyToStart(ctx, {
|
||||
sender: senderId,
|
||||
simulationId,
|
||||
agentIds,
|
||||
})
|
||||
log('success', 'Published fake GPS readyToStart')
|
||||
}
|
||||
|
||||
if(argv.fakeAgentsReady) {
|
||||
log('action', `Faking readyToStart for ${agentIds.length} agent(s)...`)
|
||||
for(const agentId of agentIds) {
|
||||
await publishFakeReadyToStart(ctx, {
|
||||
sender: agentId,
|
||||
simulationId,
|
||||
})
|
||||
}
|
||||
log('success', `Published fake readyToStart for ${agentIds.length} agent(s)`)
|
||||
}
|
||||
}
|
||||
|
||||
function waitForLifecycleEvent(ctx, eventType, timeoutMs) {
|
||||
return(new Promise((resolve, reject) => {
|
||||
const lifecyclePattern = ctx.config.maestro.lifecycle.arenaChannel
|
||||
@@ -99,6 +147,16 @@ export function configureYargs(yargsBuilder) {
|
||||
default: 15000,
|
||||
type: 'number',
|
||||
},
|
||||
fakeAgentsReady: {
|
||||
describe: 'After onYourMarks, publish fake readyToStart for each seeded agent',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
fakeGpsReady: {
|
||||
describe: 'After onYourMarks, publish fake GPS readyToStart',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -163,24 +221,29 @@ export async function run(ctx) {
|
||||
|
||||
log('success', `Received onYourMarks for simulationId=${payload.simulationId}`)
|
||||
|
||||
log('action', 'Reading arena store...')
|
||||
const indexIds = await arenaCnx.redisSmembers(arenaStorage.agentsIndexKey)
|
||||
const expectedIds = [...expectedById.keys()].sort()
|
||||
const actualIds = [...indexIds].sort()
|
||||
|
||||
if(actualIds.length !== expectedIds.length) {
|
||||
throw(new Error(`Agent index count mismatch: expected ${expectedIds.length}, got ${actualIds.length}`))
|
||||
const expectedIds = [...expectedById.keys()]
|
||||
if(argv.fakeAgentsReady || argv.fakeGpsReady) {
|
||||
await publishFakeReadies(ctx, payload.simulationId, expectedIds)
|
||||
}
|
||||
|
||||
for(let i = 0; i < expectedIds.length; i++) {
|
||||
if(actualIds[i] !== expectedIds[i]) {
|
||||
throw(new Error(`Agent index mismatch at ${i}: expected ${expectedIds[i]}, got ${actualIds[i]}`))
|
||||
log('action', 'Reading arena store...')
|
||||
const indexIds = await arenaCnx.redisSmembers(arenaStorage.agentsIndexKey)
|
||||
const sortedExpectedIds = [...expectedIds].sort()
|
||||
const actualIds = [...indexIds].sort()
|
||||
|
||||
if(actualIds.length !== sortedExpectedIds.length) {
|
||||
throw(new Error(`Agent index count mismatch: expected ${sortedExpectedIds.length}, got ${actualIds.length}`))
|
||||
}
|
||||
|
||||
for(let i = 0; i < sortedExpectedIds.length; i++) {
|
||||
if(actualIds[i] !== sortedExpectedIds[i]) {
|
||||
throw(new Error(`Agent index mismatch at ${i}: expected ${sortedExpectedIds[i]}, got ${actualIds[i]}`))
|
||||
}
|
||||
}
|
||||
|
||||
log('success', `Arena agents index contains ${actualIds.length} agent(s)`)
|
||||
|
||||
for(const agentId of expectedIds) {
|
||||
for(const agentId of sortedExpectedIds) {
|
||||
const key = agentHashKey(arenaStorage.agentHashKey, agentId)
|
||||
const hash = await arenaCnx.redisHgetall(key)
|
||||
const expected = expectedById.get(agentId)
|
||||
@@ -218,5 +281,9 @@ export async function run(ctx) {
|
||||
log('success', `Agent ${agentId}: position, vector, and store values match MySQL`)
|
||||
}
|
||||
|
||||
log('success', 'Arena store seeded correctly from MySQL (Maestro will wait for agent + primordial daemon readyToStart until timeout)')
|
||||
if(argv.fakeAgentsReady || argv.fakeGpsReady) {
|
||||
log('success', 'Arena store seeded correctly from MySQL; fake prepare acks published')
|
||||
} else {
|
||||
log('success', 'Arena store seeded correctly from MySQL (Maestro will wait for agent + primordial daemon readyToStart until timeout)')
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user