test: retry transient unauthenticated upload probe
This commit is contained in:
@@ -4,6 +4,7 @@ import test from 'node:test'
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
confirmedNetSummary,
|
confirmedNetSummary,
|
||||||
|
isTransientGatewayFailure,
|
||||||
normalizeWeightPalletOptionPage,
|
normalizeWeightPalletOptionPage,
|
||||||
normalizedGrossKg,
|
normalizedGrossKg,
|
||||||
palletOptionsPath,
|
palletOptionsPath,
|
||||||
@@ -13,6 +14,15 @@ import {
|
|||||||
workspaceWeightMatchesBaseline,
|
workspaceWeightMatchesBaseline,
|
||||||
} from './inbound-weight-ocr.mjs'
|
} from './inbound-weight-ocr.mjs'
|
||||||
|
|
||||||
|
test('retries only transient gateway failures for the unauthenticated upload probe', () => {
|
||||||
|
assert.equal(isTransientGatewayFailure({ http: 0 }), true)
|
||||||
|
assert.equal(isTransientGatewayFailure({ http: 502 }), true)
|
||||||
|
assert.equal(isTransientGatewayFailure({ http: 503 }), true)
|
||||||
|
assert.equal(isTransientGatewayFailure({ http: 401 }), false)
|
||||||
|
assert.equal(isTransientGatewayFailure({ http: 403 }), false)
|
||||||
|
assert.equal(isTransientGatewayFailure({ http: 500 }), false)
|
||||||
|
})
|
||||||
|
|
||||||
test('selects a stable complete pallet snapshot without status or availability', () => {
|
test('selects a stable complete pallet snapshot without status or availability', () => {
|
||||||
const selected = selectWeightPallet([
|
const selected = selectWeightPallet([
|
||||||
{ palletId: '20', palletCode: 'P-20', palletType: 'STANDARD', capacityCbm: 2, tareWeightKg: 18.5 },
|
{ palletId: '20', palletCode: 'P-20', palletType: 'STANDARD', capacityCbm: 2, tareWeightKg: 18.5 },
|
||||||
|
|||||||
@@ -72,6 +72,20 @@ function expectedRejection(response) {
|
|||||||
return response?.http === 200 && response?.body && String(response.body.code) !== '200'
|
return response?.http === 200 && response?.body && String(response.body.code) !== '200'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isTransientGatewayFailure(response) {
|
||||||
|
return response?.http === 0 || response?.http === 502 || response?.http === 503
|
||||||
|
}
|
||||||
|
|
||||||
|
async function unauthenticatedMultipart(context, path, file) {
|
||||||
|
let response = null
|
||||||
|
for (let attempt = 1; attempt <= 3; attempt += 1) {
|
||||||
|
response = await multipart(context, path, file, '')
|
||||||
|
if (!isTransientGatewayFailure(response) || attempt === 3) return response
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, attempt * 750))
|
||||||
|
}
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|
||||||
function markerVisible(detail, marker) {
|
function markerVisible(detail, marker) {
|
||||||
const values = [
|
const values = [
|
||||||
detail?.publicRemark,
|
detail?.publicRemark,
|
||||||
@@ -435,7 +449,7 @@ export async function run(context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const uploadPath = `/api/platform/v1/files/measurements/${encodeURIComponent(target.tenantId)}/${encodeURIComponent(target.inboundId)}`
|
const uploadPath = `/api/platform/v1/files/measurements/${encodeURIComponent(target.tenantId)}/${encodeURIComponent(target.inboundId)}`
|
||||||
const noAuth = await multipart(context, uploadPath, image, '')
|
const noAuth = await unauthenticatedMultipart(context, uploadPath, image)
|
||||||
context.assert(MODULE, '未认证请求不能上传称重图片', noAuth,
|
context.assert(MODULE, '未认证请求不能上传称重图片', noAuth,
|
||||||
noAuth.http === 401 || noAuth.http === 403,
|
noAuth.http === 401 || noAuth.http === 403,
|
||||||
`HTTP=${noAuth.http}, code=${noAuth.body?.code ?? 'none'}`, SCENARIO_OPTIONS)
|
`HTTP=${noAuth.http}, code=${noAuth.body?.code ?? 'none'}`, SCENARIO_OPTIONS)
|
||||||
|
|||||||
Reference in New Issue
Block a user