1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// @api:src/queue_length_estimates.rs
// @impl:src/queue_length_estimates_inner.rs
// @test:tests/queue_length_estimates_test.rs
// @design-doc:design/queue-length-estimates/07-design/call-chain.md
/// 契约:src/queue_length_estimates.rs:22
/// @api:src/queue_length_estimates.rs
/// @impl:src/queue_length_estimates_inner.rs
/// @kind: contract
/// @critical
/// Scenario: public_queries_do_not_allocate_on_the_calling_thread
/// Given 已准备空池和串行并发均非空的池,线程局部分配计数器已由真实分配校验有效
/// When 仅在每次公共查询调用期间开启当前线程的分配监测,各池查询100次
/// Then alloc、alloc_zeroed和realloc调用数均为零,其他线程分配不计入
/// 契约:src/queue_length_estimates.rs:4-6,19-23
/// @api:src/queue_length_estimates.rs
/// @impl:src/queue_length_estimates_inner.rs
/// @kind: contract
/// @critical
/// Scenario: empty_pool_returns_all_zeroes_through_shared_borrow
/// Given 新建空池并将其借用为非static共享引用
/// When 查询全部队列估计
/// Then 返回serial的21个零和parallel的5个零
/// 契约:src/queue_length_estimates.rs:5-6;design/queue-length-estimates/01-requirements/needs.md:8-9
/// @api:src/queue_length_estimates.rs
/// @impl:src/queue_length_estimates_inner.rs
/// @kind: contract
/// @critical
/// Scenario: serial_bands_and_all_group_positions_are_decoded
/// Given 每组按轮换排列提交0、1、16、17、32、33、49个任务,共七轮独立池
/// When 每轮查询全部队列估计
/// Then 对应估计分别为0、16、16、32、32、48、48,覆盖全部21组及首末组
/// 契约:src/queue_length_estimates.rs:7,25
/// @api:src/queue_length_estimates.rs
/// @impl:src/queue_length_estimates_inner.rs
/// @kind: contract
/// @critical
/// Scenario: occupied_groups_keep_waiting_estimates_without_counting_used
/// Given 组0排队18个任务、组20排队1个任务,并各取出一个且持有句柄
/// When 重复查询占用中的组
/// Then 组0仍报32、组20报0,其余项为零;查询不解除占用,释放后组0余下17个任务可按序取得
/// 契约:src/queue_length_estimates.rs:5-6;design/queue-length-estimates/01-requirements/needs.md:11-12
/// @api:src/queue_length_estimates.rs
/// @impl:src/queue_length_estimates_inner.rs
/// @kind: contract
/// @critical
/// Scenario: parallel_fields_preserve_order_and_saturate_independently
/// Given 五档依次为最低至最高,分别构造全零、不同非零值、上限减1、上限、上限加1五组独立池
/// When 查询每个池
/// Then 各档对应原提示,上限分别为8191、8191、8191、8191、4095,超过上限时截断且字段互不污染
/// 契约:src/queue_length_estimates.rs:21-25;design/queue-length-estimates/01-requirements/needs.md:14-15
/// @api:src/queue_length_estimates.rs
/// @impl:src/queue_length_estimates_inner.rs
/// @kind: contract
/// @critical
/// Scenario: repeated_queries_preserve_tasks_and_never_call_executor
/// Given 组0有任务10、11、12,最低档有任务20、21,且执行器三个回调均计数
/// When 连续查询100次
/// Then 每次返回组0为16、最低档为2且其他项零;三个回调计数不变,全部5个任务仍恰好取得一次
/// 契约:src/queue_length_estimates.rs:9-15,20
/// @api:src/queue_length_estimates.rs
/// @impl:src/queue_length_estimates_inner.rs
/// @kind: contract
/// @critical
/// Scenario: returned_arrays_are_independently_owned
/// Given 组20有任务7、最高档有任务8,并已取得一份查询结果
/// When 把该结果的两个数组全部改成usize最大值后重新查询
/// Then 新结果仍只有组20为16、最高档为1,原结果保持调用方写入值
/// 契约:src/queue_length_estimates.rs:7-8,25
/// @api:src/queue_length_estimates.rs
/// @impl:src/queue_length_estimates_inner.rs
/// @kind: contract
/// @critical
/// Scenario: fast_accepted_tasks_are_not_added_to_estimates
/// Given 执行器阈值100且空闲并接受任务,组0提交7、最高档提交8,接受计数为2
/// When 重复查询
/// Then 全26项为零,接受计数仍为2且池无排队任务
/// 契约:src/queue_length_estimates.rs:6,8,22,24
/// @api:src/queue_length_estimates.rs
/// @impl:src/queue_length_estimates_inner.rs
/// @kind: contract
/// @critical
/// Scenario: concurrent_queries_stay_in_range_and_preserve_all_tasks
/// Given 两个生产者和两个观察者同时起跑,生产者持续向组20提交偶数编号、向最高档提交奇数编号,直到两个观察者完成
/// When 每个观察者先查询并记录提交进度,再自由交错查询至少2000次,直到两个生产者的提交计数都超过该起点
/// Then 每次serial只取0、16、32、48且parallel前四项不超过8191、末项不超过4095;每个查询窗口内两生产者均有提交进展,回调仅来自提交,最终按提交计数核对全部任务各一次,不要求统一快照