Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
R
RoboPLC
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄新宇
RoboPLC
Commits
2cbe39c4
提交
2cbe39c4
authored
3月 07, 2024
作者:
Serhij S
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
insta tests
上级
36e67c8d
隐藏空白字符变更
内嵌
并排
正在显示
24 个修改的文件
包含
464 行增加
和
27 行删除
+464
-27
Cargo.toml
Cargo.toml
+1
-0
hub.rs
src/hub.rs
+5
-7
hub_async.rs
src/hub_async.rs
+8
-10
pchannel.rs
src/pchannel.rs
+10
-3
pchannel_async.rs
src/pchannel_async.rs
+10
-3
roboplc__hub__test__hub-2.snap
src/snapshots/roboplc__hub__test__hub-2.snap
+66
-0
roboplc__hub__test__hub.snap
src/snapshots/roboplc__hub__test__hub.snap
+5
-0
roboplc__hub_async__test__hub-2.snap
src/snapshots/roboplc__hub_async__test__hub-2.snap
+66
-0
roboplc__hub_async__test__hub.snap
src/snapshots/roboplc__hub_async__test__hub.snap
+5
-0
roboplc__pchannel__test__delivery_policy_optional-2.snap
.../roboplc__pchannel__test__delivery_policy_optional-2.snap
+66
-0
roboplc__pchannel__test__delivery_policy_optional.snap
...ts/roboplc__pchannel__test__delivery_policy_optional.snap
+5
-0
roboplc__pchannel__test__delivery_policy_single-2.snap
...ts/roboplc__pchannel__test__delivery_policy_single-2.snap
+5
-0
roboplc__pchannel__test__delivery_policy_single-3.snap
...ts/roboplc__pchannel__test__delivery_policy_single-3.snap
+49
-0
roboplc__pchannel__test__delivery_policy_single.snap
...hots/roboplc__pchannel__test__delivery_policy_single.snap
+5
-0
roboplc__pchannel_async__test__delivery_policy_optional-2.snap
...lc__pchannel_async__test__delivery_policy_optional-2.snap
+66
-0
roboplc__pchannel_async__test__delivery_policy_optional.snap
...oplc__pchannel_async__test__delivery_policy_optional.snap
+5
-0
roboplc__pchannel_async__test__delivery_policy_single-2.snap
...oplc__pchannel_async__test__delivery_policy_single-2.snap
+5
-0
roboplc__pchannel_async__test__delivery_policy_single-3.snap
...oplc__pchannel_async__test__delivery_policy_single-3.snap
+49
-0
roboplc__pchannel_async__test__delivery_policy_single.snap
...oboplc__pchannel_async__test__delivery_policy_single.snap
+5
-0
roboplc__ttlcell__test__get_set-2.snap
src/snapshots/roboplc__ttlcell__test__get_set-2.snap
+5
-0
roboplc__ttlcell__test__get_set-3.snap
src/snapshots/roboplc__ttlcell__test__get_set-3.snap
+7
-0
roboplc__ttlcell__test__get_set-4.snap
src/snapshots/roboplc__ttlcell__test__get_set-4.snap
+5
-0
roboplc__ttlcell__test__get_set.snap
src/snapshots/roboplc__ttlcell__test__get_set.snap
+7
-0
ttlcell.rs
src/ttlcell.rs
+4
-4
没有找到文件。
Cargo.toml
浏览文件 @
2cbe39c4
...
...
@@ -23,4 +23,5 @@ sysinfo = "0.30.6"
thiserror
=
"1.0.57"
[dev-dependencies]
insta
=
"1.36.1"
tokio
=
{
version
=
"1.36.0"
,
features
=
[
"rt"
,
"macros"
,
"time"
]
}
src/hub.rs
浏览文件 @
2cbe39c4
...
...
@@ -307,7 +307,7 @@ mod test {
use
super
::
Hub
;
#[derive(Clone)]
#[derive(Clone
,
Debug
)]
enum
Message
{
Temperature
(
f64
),
Humidity
(
f64
),
...
...
@@ -331,13 +331,11 @@ mod test {
sender
.send
(
Message
::
Humidity
(
2.0
));
sender
.send
(
Message
::
Test
);
}
let
mut
c
=
0
;
let
mut
messages
=
Vec
::
with_capacity
(
20
)
;
while
let
Ok
(
msg
)
=
recv
.try_recv
()
{
match
msg
{
Message
::
Temperature
(
_
)
|
Message
::
Humidity
(
_
)
=>
c
+=
1
,
Message
::
Test
=>
panic!
(),
}
messages
.push
(
msg
);
}
assert_eq!
(
c
,
20
);
insta
::
assert_snapshot!
(
messages
.len
());
insta
::
assert_debug_snapshot!
(
messages
);
}
}
src/hub_async.rs
浏览文件 @
2cbe39c4
...
...
@@ -306,7 +306,7 @@ mod test {
use
super
::
Hub
;
#[derive(Clone)]
#[derive(Clone
,
Debug
)]
enum
Message
{
Temperature
(
f64
),
Humidity
(
f64
),
...
...
@@ -319,9 +319,9 @@ mod test {
async
fn
test_hub
()
{
let
hub
=
Hub
::
<
Message
>
::
new
()
.set_default_channel_capacity
(
20
);
let
sender
=
hub
.sender
();
let
recv
=
hub
let
client1
=
hub
.register
(
"test
_recv
"
,
"test
1
"
,
event_matches!
(
Message
::
Temperature
(
_
)
|
Message
::
Humidity
(
_
)),
)
.unwrap
();
...
...
@@ -330,13 +330,11 @@ mod test {
sender
.send
(
Message
::
Humidity
(
2.0
))
.await
;
sender
.send
(
Message
::
Test
)
.await
;
}
let
mut
c
=
0
;
while
let
Ok
(
msg
)
=
recv
.try_recv
()
{
match
msg
{
Message
::
Temperature
(
_
)
|
Message
::
Humidity
(
_
)
=>
c
+=
1
,
Message
::
Test
=>
panic!
(),
}
let
mut
messages
=
Vec
::
with_capacity
(
20
);
while
let
Ok
(
msg
)
=
client1
.try_recv
()
{
messages
.push
(
msg
);
}
assert_eq!
(
c
,
20
);
insta
::
assert_snapshot!
(
messages
.len
());
insta
::
assert_debug_snapshot!
(
messages
);
}
}
src/pchannel.rs
浏览文件 @
2cbe39c4
...
...
@@ -325,12 +325,16 @@ mod test {
}
});
thread
::
sleep
(
Duration
::
from_secs
(
1
));
let
mut
messages
=
Vec
::
new
();
while
let
Ok
(
msg
)
=
rx
.recv
()
{
thread
::
sleep
(
Duration
::
from_millis
(
10
));
if
matches!
(
msg
,
Message
::
Spam
)
{
panic!
(
"delivery policy not respected ({:?})"
,
msg
);
}
messages
.push
(
msg
);
}
insta
::
assert_debug_snapshot!
(
messages
.len
());
insta
::
assert_debug_snapshot!
(
messages
);
}
#[test]
...
...
@@ -348,20 +352,23 @@ mod test {
thread
::
sleep
(
Duration
::
from_secs
(
1
));
let
mut
c
=
0
;
let
mut
t
=
0
;
let
mut
messages
=
Vec
::
new
();
while
let
Ok
(
msg
)
=
rx
.recv
()
{
match
msg
{
Message
::
Test
(
_
)
=>
c
+=
1
,
Message
::
Temperature
(
_
)
=>
t
+=
1
,
Message
::
Spam
=>
{}
}
messages
.push
(
msg
);
}
assert_eq!
(
c
,
10
);
assert_eq!
(
t
,
1
);
insta
::
assert_snapshot!
(
c
);
insta
::
assert_snapshot!
(
t
);
insta
::
assert_debug_snapshot!
(
messages
);
}
#[test]
fn
test_poisoning
()
{
let
n
=
20
_000
;
let
n
=
5
_000
;
for
i
in
0
..
n
{
let
(
tx
,
rx
)
=
bounded
::
<
Message
>
(
512
);
let
rx_t
=
thread
::
spawn
(
move
||
while
rx
.recv
()
.is_ok
()
{});
...
...
src/pchannel_async.rs
浏览文件 @
2cbe39c4
...
...
@@ -490,12 +490,16 @@ mod test {
}
});
thread
::
sleep
(
Duration
::
from_secs
(
1
));
let
mut
messages
=
Vec
::
new
();
while
let
Ok
(
msg
)
=
rx
.recv
()
.await
{
thread
::
sleep
(
Duration
::
from_millis
(
10
));
if
matches!
(
msg
,
Message
::
Spam
)
{
panic!
(
"delivery policy not respected ({:?})"
,
msg
);
}
messages
.push
(
msg
);
}
insta
::
assert_debug_snapshot!
(
messages
.len
());
insta
::
assert_debug_snapshot!
(
messages
);
}
#[tokio
::
test]
...
...
@@ -513,20 +517,23 @@ mod test {
thread
::
sleep
(
Duration
::
from_secs
(
1
));
let
mut
c
=
0
;
let
mut
t
=
0
;
let
mut
messages
=
Vec
::
new
();
while
let
Ok
(
msg
)
=
rx
.recv
()
.await
{
match
msg
{
Message
::
Test
(
_
)
=>
c
+=
1
,
Message
::
Temperature
(
_
)
=>
t
+=
1
,
Message
::
Spam
=>
{}
}
messages
.push
(
msg
);
}
assert_eq!
(
c
,
10
);
assert_eq!
(
t
,
1
);
insta
::
assert_snapshot!
(
c
);
insta
::
assert_snapshot!
(
t
);
insta
::
assert_debug_snapshot!
(
messages
);
}
#[tokio
::
test]
async
fn
test_poisoning
()
{
let
n
=
20
_000
;
let
n
=
5
_000
;
for
_
in
0
..
n
{
let
(
tx
,
rx
)
=
bounded
::
<
Message
>
(
512
);
let
rx_t
=
tokio
::
spawn
(
async
move
{
while
rx
.recv
()
.await
.is_ok
()
{}
});
...
...
src/snapshots/roboplc__hub__test__hub-2.snap
0 → 100644
浏览文件 @
2cbe39c4
---
source: src/hub.rs
expression: messages
---
[
Temperature(
1.0,
),
Humidity(
2.0,
),
Temperature(
1.0,
),
Humidity(
2.0,
),
Temperature(
1.0,
),
Humidity(
2.0,
),
Temperature(
1.0,
),
Humidity(
2.0,
),
Temperature(
1.0,
),
Humidity(
2.0,
),
Temperature(
1.0,
),
Humidity(
2.0,
),
Temperature(
1.0,
),
Humidity(
2.0,
),
Temperature(
1.0,
),
Humidity(
2.0,
),
Temperature(
1.0,
),
Humidity(
2.0,
),
Temperature(
1.0,
),
Humidity(
2.0,
),
]
src/snapshots/roboplc__hub__test__hub.snap
0 → 100644
浏览文件 @
2cbe39c4
---
source: src/hub.rs
expression: messages.len()
---
20
src/snapshots/roboplc__hub_async__test__hub-2.snap
0 → 100644
浏览文件 @
2cbe39c4
---
source: src/hub_async.rs
expression: messages
---
[
Temperature(
1.0,
),
Humidity(
2.0,
),
Temperature(
1.0,
),
Humidity(
2.0,
),
Temperature(
1.0,
),
Humidity(
2.0,
),
Temperature(
1.0,
),
Humidity(
2.0,
),
Temperature(
1.0,
),
Humidity(
2.0,
),
Temperature(
1.0,
),
Humidity(
2.0,
),
Temperature(
1.0,
),
Humidity(
2.0,
),
Temperature(
1.0,
),
Humidity(
2.0,
),
Temperature(
1.0,
),
Humidity(
2.0,
),
Temperature(
1.0,
),
Humidity(
2.0,
),
]
src/snapshots/roboplc__hub_async__test__hub.snap
0 → 100644
浏览文件 @
2cbe39c4
---
source: src/hub_async.rs
expression: messages.len()
---
20
src/snapshots/roboplc__pchannel__test__delivery_policy_optional-2.snap
0 → 100644
浏览文件 @
2cbe39c4
---
source: src/pchannel.rs
expression: messages
---
[
Test(
123,
),
Temperature(
123.0,
),
Test(
123,
),
Temperature(
123.0,
),
Test(
123,
),
Temperature(
123.0,
),
Test(
123,
),
Temperature(
123.0,
),
Test(
123,
),
Temperature(
123.0,
),
Test(
123,
),
Temperature(
123.0,
),
Test(
123,
),
Temperature(
123.0,
),
Test(
123,
),
Temperature(
123.0,
),
Test(
123,
),
Temperature(
123.0,
),
Test(
123,
),
Temperature(
123.0,
),
]
src/snapshots/roboplc__pchannel__test__delivery_policy_optional.snap
0 → 100644
浏览文件 @
2cbe39c4
---
source: src/pchannel.rs
expression: messages.len()
---
20
src/snapshots/roboplc__pchannel__test__delivery_policy_single-2.snap
0 → 100644
浏览文件 @
2cbe39c4
---
source: src/pchannel.rs
expression: t
---
1
src/snapshots/roboplc__pchannel__test__delivery_policy_single-3.snap
0 → 100644
浏览文件 @
2cbe39c4
---
source: src/pchannel.rs
expression: messages
---
[
Test(
123,
),
Spam,
Test(
123,
),
Spam,
Test(
123,
),
Spam,
Test(
123,
),
Spam,
Test(
123,
),
Spam,
Test(
123,
),
Spam,
Test(
123,
),
Spam,
Test(
123,
),
Spam,
Test(
123,
),
Spam,
Test(
123,
),
Spam,
Temperature(
123.0,
),
]
src/snapshots/roboplc__pchannel__test__delivery_policy_single.snap
0 → 100644
浏览文件 @
2cbe39c4
---
source: src/pchannel.rs
expression: c
---
10
src/snapshots/roboplc__pchannel_async__test__delivery_policy_optional-2.snap
0 → 100644
浏览文件 @
2cbe39c4
---
source: src/pchannel_async.rs
expression: messages
---
[
Test(
123,
),
Temperature(
123.0,
),
Test(
123,
),
Temperature(
123.0,
),
Test(
123,
),
Temperature(
123.0,
),
Test(
123,
),
Temperature(
123.0,
),
Test(
123,
),
Temperature(
123.0,
),
Test(
123,
),
Temperature(
123.0,
),
Test(
123,
),
Temperature(
123.0,
),
Test(
123,
),
Temperature(
123.0,
),
Test(
123,
),
Temperature(
123.0,
),
Test(
123,
),
Temperature(
123.0,
),
]
src/snapshots/roboplc__pchannel_async__test__delivery_policy_optional.snap
0 → 100644
浏览文件 @
2cbe39c4
---
source: src/pchannel_async.rs
expression: messages.len()
---
20
src/snapshots/roboplc__pchannel_async__test__delivery_policy_single-2.snap
0 → 100644
浏览文件 @
2cbe39c4
---
source: src/pchannel_async.rs
expression: t
---
1
src/snapshots/roboplc__pchannel_async__test__delivery_policy_single-3.snap
0 → 100644
浏览文件 @
2cbe39c4
---
source: src/pchannel_async.rs
expression: messages
---
[
Test(
123,
),
Spam,
Test(
123,
),
Spam,
Test(
123,
),
Spam,
Test(
123,
),
Spam,
Test(
123,
),
Spam,
Test(
123,
),
Spam,
Test(
123,
),
Spam,
Test(
123,
),
Spam,
Test(
123,
),
Spam,
Test(
123,
),
Spam,
Temperature(
123.0,
),
]
src/snapshots/roboplc__pchannel_async__test__delivery_policy_single.snap
0 → 100644
浏览文件 @
2cbe39c4
---
source: src/pchannel_async.rs
expression: c
---
10
src/snapshots/roboplc__ttlcell__test__get_set-2.snap
0 → 100644
浏览文件 @
2cbe39c4
---
source: src/ttlcell.rs
expression: opt.as_ref().copied()
---
None
src/snapshots/roboplc__ttlcell__test__get_set-3.snap
0 → 100644
浏览文件 @
2cbe39c4
---
source: src/ttlcell.rs
expression: opt.as_ref().copied()
---
Some(
30,
)
src/snapshots/roboplc__ttlcell__test__get_set-4.snap
0 → 100644
浏览文件 @
2cbe39c4
---
source: src/ttlcell.rs
expression: opt.as_ref().copied()
---
None
src/snapshots/roboplc__ttlcell__test__get_set.snap
0 → 100644
浏览文件 @
2cbe39c4
---
source: src/ttlcell.rs
expression: opt.as_ref().copied()
---
Some(
25,
)
src/ttlcell.rs
浏览文件 @
2cbe39c4
...
...
@@ -146,14 +146,14 @@ mod test {
let
ttl
=
Duration
::
from_millis
(
10
);
let
mut
opt
=
TtlCell
::
new_with_value
(
ttl
,
25
);
thread
::
sleep
(
ttl
/
2
);
assert_eq!
(
opt
.as_ref
()
.copied
(),
Some
(
25
));
insta
::
assert_debug_snapshot!
(
opt
.as_ref
()
.copied
(
));
thread
::
sleep
(
ttl
);
assert_eq!
(
opt
.as_ref
()
.copied
(),
None
);
insta
::
assert_debug_snapshot!
(
opt
.as_ref
()
.copied
()
);
opt
.set
(
30
);
thread
::
sleep
(
ttl
/
2
);
assert_eq!
(
opt
.as_ref
()
.copied
(),
Some
(
30
));
insta
::
assert_debug_snapshot!
(
opt
.as_ref
()
.copied
(
));
thread
::
sleep
(
ttl
);
assert_eq!
(
opt
.as_ref
()
.copied
(),
None
);
insta
::
assert_debug_snapshot!
(
opt
.as_ref
()
.copied
()
);
}
#[test]
fn
test_take_replace
()
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论