我有一个 api 端点,每个请求都需要是不同的 id ,但是如何为所有 VU 共享的每次迭代创建一个全局且连续的 id ,就像数据库表上的主键一样。
前任:
request 1 : <id>400</id> VU :1
request 2 : <id>401</id> VU :1
request 1 : <id>402</id> VU :2
request 3 : <id>403</id> VU :1
request 4 : <id>404</id> VU :1
request 2 : <id>405</id> VU :2
request 3 : <id>406</id> VU :2
Run Code Online (Sandbox Code Playgroud)
有没有办法声明一个由整个测试共享的变量?根据文档,Setup 和 Init 是针对每个 VU 的,不能共享数据。
我有这个代码:
function XlsToStringGrid(AGrid: TStringGrid; AXLSFile: string): Boolean;
const
xlCellTypeLastCell = $0000000B;
var
XLApp, Sheet: OLEVariant;
RangeMatrix: Variant;
x, y, k, r: Integer;
begin
Result:=False;
//Cria Excel- OLE Object
XLApp:=CreateOleObject('Excel.Application');
try
XLApp.Visible:=False;
XLApp.Workbooks.Open(AXLSFile);
Sheet:=XLApp.Workbooks[ExtractFileName(AXLSFile)].WorkSheets[1];
Sheet.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate;
x:=XLApp.ActiveCell.Row;
y:=XLApp.ActiveCell.Column;
AGrid.RowCount:=x;
AGrid.ColCount:=y;
RangeMatrix:=XLApp.Range['A1', XLApp.Cells.Item[X, Y]].Value;
k:=1;
repeat
for r:=1 to y do
AGrid.Cells[(r - 1),(k - 1)]:=RangeMatrix[K, R];
Inc(k,1);
until k > x;
RangeMatrix:=Unassigned;
Result:=True;
finally
if not VarIsEmpty(XLApp) then
begin
Sheet:=Unassigned;
XLApp.Workbooks[ExtractFileName(AXLSFile)].Close;
XLApp.Quit;
XLAPP:=Unassigned;
end;
try freeandnil(XLAPP) except; end;
try freeandnil(Sheet) except; …Run Code Online (Sandbox Code Playgroud)