mirror of
https://github.com/motajs/template.git
synced 2026-09-18 13:10:21 +08:00
fix(07-15): reject an expand multiplier of exactly one
- both multiplier checks tighten from < 1 to <= 1, matching warning 149's own text (must be greater than 1) - an exact multiplier of 1 now warns 149 and falls back to the existing factor 2, so buffer expansion always terminates - add the multiplier-of-one regression case (two code 149 warnings, 15 appended steps all read back in order)
This commit is contained in:
parent
a7c9f97c94
commit
49116c0784
@ -1,4 +1,4 @@
|
||||
// 测试 ReplayArray 构件级行为:单类型参数编解码与单数组操作单次读回、不可编码参数丢弃后的计数与偏移对齐
|
||||
// 测试 ReplayArray 构件级行为:单类型参数编解码与单数组操作单次读回、不可编码参数丢弃后的计数与偏移对齐、乘数恰为 1 的边界
|
||||
import { logger } from '@motajs/common';
|
||||
import { afterAll, describe, expect, it, vi } from 'vitest';
|
||||
import { ReplayArray } from './array';
|
||||
@ -1056,6 +1056,33 @@ describe('ReplayArray expand and width warnings', () => {
|
||||
expect(info.map(v => v.code)).toEqual([149, 149]);
|
||||
});
|
||||
|
||||
// 验证扩容乘数恰为 1 时按码 149 拒绝两个乘数并回退倍率,扩容仍能终止且全部步骤读回
|
||||
it('warns code 149 and still expands when an expand multiplier is exactly 1', () => {
|
||||
const { ret, info } = logger.catch(() =>
|
||||
createArray({
|
||||
initCommandLength: 2,
|
||||
initParamLength: 8,
|
||||
commandExpandMultiplier: 1,
|
||||
paramExpandMultiplier: 1
|
||||
})
|
||||
);
|
||||
const array = ret;
|
||||
|
||||
expect(info.map(v => v.code)).toEqual([149, 149]);
|
||||
|
||||
for (let i = 0; i < 15; i++) {
|
||||
array.add(i, [i]);
|
||||
}
|
||||
|
||||
expect(array.length).toBe(15);
|
||||
const stream = array.createReadStream(0);
|
||||
for (let i = 0; i < 15; i++) {
|
||||
expectStepTyped(stream.read()!, i, [i], i + 1);
|
||||
}
|
||||
expect(stream.read()).toBeNull();
|
||||
expect(stream.index).toBe(15);
|
||||
});
|
||||
|
||||
// 验证指令数组达到上限后触发告警码 150
|
||||
it('warns code 150 when the command array is full', () => {
|
||||
const array = createArray({
|
||||
|
||||
@ -110,7 +110,7 @@ export class ReplayArray implements IReplayArray {
|
||||
this.commandMax = config.commandMaxLength;
|
||||
this.paramMax = config.paramMaxLength;
|
||||
|
||||
if (config.commandExpandMultiplier < 1) {
|
||||
if (config.commandExpandMultiplier <= 1) {
|
||||
const str = config.commandExpandMultiplier.toString();
|
||||
logger.warn(149, 'command', str);
|
||||
this.commandExpand = 2;
|
||||
@ -118,7 +118,7 @@ export class ReplayArray implements IReplayArray {
|
||||
this.commandExpand = config.commandExpandMultiplier;
|
||||
}
|
||||
|
||||
if (config.paramExpandMultiplier < 1) {
|
||||
if (config.paramExpandMultiplier <= 1) {
|
||||
const str = config.paramExpandMultiplier.toString();
|
||||
logger.warn(149, 'param', str);
|
||||
this.paramExpand = 2;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user