Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
zombienet-sdk
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
Mirrored projects
zombienet-sdk
Commits
69258dd3
Verified
Commit
69258dd3
authored
1 year ago
by
Loris Moulin
Browse files
Options
Downloads
Patches
Plain Diff
feat: added namespace generate_files and destroy happy path test, fixed tests
parent
0b10aa9b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
crates/provider/src/native.rs
+152
-19
152 additions, 19 deletions
crates/provider/src/native.rs
with
152 additions
and
19 deletions
crates/provider/src/native.rs
+
152
−
19
View file @
69258dd3
...
...
@@ -636,12 +636,17 @@ mod tests {
let
namespace
=
provider
.create_namespace
()
.await
.unwrap
();
// ensure namespace directory is created
assert!
(
fs
.files
.read
()
.await
.contains_key
(
namespace
.base_dir
()
.as_os_str
()));
// ensure namespace is added to provider namespaces
assert_eq!
(
provider
.namespaces
()
.await
.len
(),
1
);
// ensure the only provider namespace is the same one as the one we just created
assert!
(
provider
.namespaces
()
.await
.get
(
namespace
.id
())
.is_some
());
}
...
...
@@ -794,13 +799,15 @@ mod tests {
}
})
.collect
::
<
Vec
<
Process
>>
();
// ensure only one dummy process exists
assert_eq!
(
processes
.len
(),
1
);
let
node_process
=
processes
.first
()
.unwrap
();
// ensure process has correct state
assert!
(
matches!
(
node_process
.stat
()
.unwrap
()
.state
()
.unwrap
(),
// pocess can be running or sleeping because we sleep between echo calls
// p
r
ocess can be running or sleeping because we sleep between echo calls
procfs
::
process
::
ProcState
::
Running
|
procfs
::
process
::
ProcState
::
Sleeping
));
...
...
@@ -834,41 +841,167 @@ mod tests {
"MY_VALUE_3"
);
// ensure log file is created and logs are written
0.
5s after process start
sleep
(
Duration
::
from_
milli
s
(
5
00
))
.await
;
assert!
(
matches!
(
// ensure log file is created and logs are written 5s after process start
sleep
(
Duration
::
from_
sec
s
(
5
))
.await
;
assert!
(
fs
.files
.read
()
.await
.get
(
node
.log_path
()
.as_os_str
())
.unwrap
(),
InMemoryFile
::
File
{
contents
,
..
}
if
contents
==
"Line 1
\n
"
.as_bytes
()
));
.unwrap
()
.contents
()
.unwrap
()
.lines
()
.count
()
>=
2
);
// ensure logs are updated when process continue running 1
.5 sec
after process start
sleep
(
Duration
::
from_
millis
(
1000
))
.await
;
assert!
(
matches!
(
// ensure logs are updated when process continue running 1
0s
after process start
sleep
(
Duration
::
from_
secs
(
5
))
.await
;
assert!
(
fs
.files
.read
()
.await
.get
(
node
.log_path
()
.as_os_str
())
.unwrap
(),
InMemoryFile
::
File
{
contents
,
..
}
if
contents
==
"Line 1
\n
Line 2
\n
"
.as_bytes
()
));
.unwrap
()
.contents
()
.unwrap
()
.lines
()
.count
()
>=
4
);
// ensure logs are updated when process continue running
2.5 sec
after process start
sleep
(
Duration
::
from_
millis
(
1000
))
.await
;
assert!
(
matches!
(
// ensure logs are updated when process continue running
15s
after process start
sleep
(
Duration
::
from_
secs
(
5
))
.await
;
assert!
(
fs
.files
.read
()
.await
.get
(
node
.log_path
()
.as_os_str
())
.unwrap
(),
InMemoryFile
::
File
{
contents
,
..
}
if
contents
==
"Line 1
\n
Line 2
\n
Line 3
\n
"
.as_bytes
()
));
.unwrap
()
.contents
()
.unwrap
()
.lines
()
.count
()
>=
6
);
// ensure node is present in namespace
assert_eq!
(
namespace
.nodes
()
.await
.len
(),
1
);
assert!
(
namespace
.nodes
()
.await
.get
(
node
.name
())
.is_some
());
}
#[tokio::test]
async
fn
namespace_generate_files_method_should_create_files_at_the_correct_locations_using_given_commands
(
)
{
let
fs
=
InMemoryFileSystem
::
new
(
HashMap
::
from
([
(
OsString
::
from_str
(
"/"
)
.unwrap
(),
InMemoryFile
::
dir
()),
(
OsString
::
from_str
(
"/tmp"
)
.unwrap
(),
InMemoryFile
::
dir
()),
]));
let
provider
=
NativeProvider
::
new
(
fs
.clone
());
let
namespace
=
provider
.create_namespace
()
.await
.unwrap
();
namespace
.generate_files
(
GenerateFilesOptions
::
new
(
vec!
[
GenerateFileCommand
::
new
(
"echo"
,
"/myfile1"
)
.args
(
vec!
[
"My file 1"
]),
GenerateFileCommand
::
new
(
"sh"
,
"/myfile2"
)
.args
(
vec!
[
"-c"
,
"echo -n $MY_CONTENT"
])
.env
(
vec!
[(
"MY_CONTENT"
,
"My file 2"
)]),
]))
.await
.unwrap
();
// ensure files have been generated correctly to right location
assert_eq!
(
fs
.files
.read
()
.await
.get
(
&
OsString
::
from_str
(
&
format!
(
"{}/myfile1"
,
namespace
.base_dir
()
.to_string_lossy
()
))
.unwrap
()
)
.unwrap
()
.contents
()
.unwrap
(),
"My file 1
\n
"
);
assert_eq!
(
fs
.files
.read
()
.await
.get
(
&
OsString
::
from_str
(
&
format!
(
"{}/myfile2"
,
namespace
.base_dir
()
.to_string_lossy
()
))
.unwrap
()
)
.unwrap
()
.contents
()
.unwrap
(),
"My file 2"
);
// ensure temporary node has been destroyed
assert_eq!
(
namespace
.nodes
()
.await
.len
(),
0
);
}
#[tokio::test]
async
fn
namespace_destroy_should_destroy_all_namespace_nodes_and_namespace_itself
()
{
let
fs
=
InMemoryFileSystem
::
new
(
HashMap
::
from
([
(
OsString
::
from_str
(
"/"
)
.unwrap
(),
InMemoryFile
::
dir
()),
(
OsString
::
from_str
(
"/tmp"
)
.unwrap
(),
InMemoryFile
::
dir
()),
]));
let
provider
=
NativeProvider
::
new
(
fs
.clone
());
let
namespace
=
provider
.create_namespace
()
.await
.unwrap
();
// spawn 2 dummy nodes to populate namespace
namespace
.spawn_node
(
SpawnNodeOptions
::
new
(
"mynode1"
,
"/home/user/Work/parity/zombienet-sdk/crates/provider/testing/dummy_node"
,
))
.await
.unwrap
();
namespace
.spawn_node
(
SpawnNodeOptions
::
new
(
"mynode2"
,
"/home/user/Work/parity/zombienet-sdk/crates/provider/testing/dummy_node"
,
))
.await
.unwrap
();
// ensure nodes are presents
assert_eq!
(
namespace
.nodes
()
.await
.len
(),
2
);
namespace
.destroy
()
.await
.unwrap
();
// ensure nodes are destroyed
assert_eq!
(
namespace
.nodes
()
.await
.len
(),
0
);
// retrieve running process
let
processes
=
procfs
::
process
::
all_processes
()
.unwrap
()
.filter_map
(|
process
|
{
if
let
Ok
(
process
)
=
process
{
process
.cmdline
()
.iter
()
.any
(|
args
|
args
.iter
()
.any
(|
arg
|
arg
.contains
(
"dummy_node"
)))
.then
(||
process
)
}
else
{
None
}
})
.collect
::
<
Vec
<
Process
>>
();
// ensure no running process exists
assert_eq!
(
processes
.len
(),
0
);
// ensure namespace is destroyed
assert_eq!
(
provider
.namespaces
()
.await
.len
(),
0
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment