Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
bdca240f
MegEngine
项目概览
MegEngine 天元
/
MegEngine
1 年多 前同步成功
通知
403
Star
4705
Fork
582
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
MegEngine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
bdca240f
编写于
12月 30, 2021
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test(fastrun): add more tests for various persistent cache
GitOrigin-RevId: 45c45c8f19281868e848a6688d3c56714da35ffd
上级
1657b8e8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
66 addition
and
11 deletion
+66
-11
imperative/python/requires-test.txt
imperative/python/requires-test.txt
+1
-0
imperative/python/test/unit/utils/test_utils.py
imperative/python/test/unit/utils/test_utils.py
+65
-11
未找到文件。
imperative/python/requires-test.txt
浏览文件 @
bdca240f
...
...
@@ -2,3 +2,4 @@ pytest==5.3.0
pytest-sphinx==0.3.1
tensorboardX==2.4
six==1.16.0
redislite ; platform_system == "Linux" or platform_system == "Darwin"
imperative/python/test/unit/utils/test_utils.py
浏览文件 @
bdca240f
import
os
import
platform
import
pytest
from
megengine.utils.persistent_cache
import
_manager
from
megengine.utils.persistent_cache
import
PersistentCacheOnServer
@
pytest
.
mark
.
parametrize
(
"with_flag"
,
[
True
,
False
])
@
pytest
.
mark
.
skipif
(
platform
.
system
()
not
in
{
"Linux"
,
"Darwin"
},
reason
=
"redislite not implemented in windows"
,
)
def
test_persistent_cache_redis
(
monkeypatch
,
with_flag
):
import
redislite
server
=
redislite
.
Redis
()
monkeypatch
.
delenv
(
"MGE_FASTRUN_CACHE_TYPE"
,
raising
=
False
)
monkeypatch
.
setenv
(
"MGE_FASTRUN_CACHE_URL"
,
"redis+socket://{}"
.
format
(
server
.
socket_file
)
)
if
with_flag
:
server
.
set
(
"mgb-cache-flag"
,
1
)
pc
=
PersistentCacheOnServer
()
pc
.
put
(
"test"
,
"hello"
,
"world"
)
if
with_flag
:
pc
=
PersistentCacheOnServer
()
assert
pc
.
get
(
"test"
,
"hello"
)
==
b
"world"
assert
pc
.
config
.
type
==
"redis"
else
:
assert
pc
.
config
.
type
==
"in-file"
def
test_persistent_cache_file
(
monkeypatch
,
tmp_path
):
monkeypatch
.
setenv
(
"MGE_FASTRUN_CACHE_TYPE"
,
"FILE"
)
monkeypatch
.
setenv
(
"MGE_FASTRUN_CACHE_DIR"
,
tmp_path
)
pc
=
PersistentCacheOnServer
()
pc
.
put
(
"test"
,
"store"
,
"this"
)
assert
pc
.
config
.
type
==
"in-file"
del
pc
pc
=
PersistentCacheOnServer
()
assert
pc
.
get
(
"test"
,
"store"
)
==
b
"this"
def
test_persistent_cache_file_clear
(
monkeypatch
,
tmp_path
):
monkeypatch
.
setenv
(
"MGE_FASTRUN_CACHE_TYPE"
,
"FILE"
)
monkeypatch
.
setenv
(
"MGE_FASTRUN_CACHE_DIR"
,
tmp_path
)
pc
=
PersistentCacheOnServer
()
pc_dummy
=
PersistentCacheOnServer
()
pc
.
put
(
"test"
,
"drop"
,
"this"
)
assert
pc
.
config
.
type
==
"in-file"
del
pc
# this dummy instance shouldn't override cache file
del
pc_dummy
os
.
unlink
(
os
.
path
.
join
(
tmp_path
,
"cache.bin"
))
pc
=
PersistentCacheOnServer
()
assert
pc
.
get
(
"test"
,
"drop"
)
is
None
def
test_persistent_cache
(
):
pc
=
_manager
k0
=
b
"
\x00\x00
"
k1
=
b
"
\x00\x01
"
cat
=
"test"
pc
.
put
(
cat
,
k0
,
k1
)
pc
.
put
(
cat
,
k1
,
k0
)
assert
k1
==
pc
.
get
(
cat
,
k0
)
assert
k0
==
pc
.
get
(
cat
,
k1
)
assert
pc
.
get
(
"test
1"
,
k0
)
==
None
def
test_persistent_cache
_memory
(
monkeypatch
):
monkeypatch
.
setenv
(
"MGE_FASTRUN_CACHE_TYPE"
,
"MEMORY"
)
pc
=
PersistentCacheOnServer
()
assert
pc
.
config
is
None
pc
.
put
(
"test"
,
"drop"
,
"this"
)
assert
pc
.
config
.
type
==
"in-memory"
assert
pc
.
get
(
"test"
,
"drop"
)
==
b
"this"
del
pc
pc
=
PersistentCacheOnServer
(
)
assert
pc
.
get
(
"test
"
,
"drop"
)
is
None
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录