-
Notifications
You must be signed in to change notification settings - Fork 6
TC-3071 add upload advisory and delete advisory scale test #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
.cargo/config.toml
Outdated
| @@ -0,0 +1,2 @@ | |||
| [env] | |||
| CARGO_WORKSPACE_ROOT = { value = "", relative = true } No newline at end of file | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it not possible to use CARGO_MANIFEST_DIR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CARGO_WORKSPACE_ROOT and CARGO_MANIFEST_DIR serve the same purpose, and I think CARGO_WORKSPACE_ROOT is more semantically appropriate. Could you please explain why CARGO_MANIFEST_DIR would be more reasonable?
.cargo/config.toml
Outdated
| @@ -0,0 +1,2 @@ | |||
| [env] | |||
| CARGO_MANIFEST_DIR = { value = "", relative = true } No newline at end of file | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable is provided by the cargo build. It does not need to be provided.
src/scenario/mod.rs
Outdated
| fn load_advisory_files(&self) -> anyhow::Result<Vec<PathBuf>> { | ||
| // Try UPLOAD_FILE_PATH first, then fall back to CARGO_MANIFEST_DIR | ||
| let base_path = std::env::var("UPLOAD_FILE_PATH") | ||
| .or_else(|_| std::env::var("CARGO_MANIFEST_DIR")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to use env! in this case. As it is a build time variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, why not use the current working directory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just want it to be as flexibly configurable as SCENARIO_FILE.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you use env to access CARGO_MANIFEST_DIR, you will get an absolute path. Isn’t this potentially unreasonable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would it be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok please check again.
src/restapi.rs
Outdated
| advisory_file: String, | ||
| user: &mut GooseUser, | ||
| ) -> Result<String, Box<TransactionError>> { | ||
| let file_bytes = tokio::fs::read(&advisory_file).await.map_err(|e| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Part of this test now is the loading of the file. Which won't change. Can we cache that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a hard-coded list of a number of files will run into the same situation. Just a bit later.
I think the appropriate solution for this would be to:
- load an example file on startup, hard-coded, only one
- create a function returning a new file. in-memory
- implement that function in a way that it generates a new version of the file by modifying certain element with random values (e.g. adding a random suffix to all package names)
- use this function to generate the content each time it's required during the test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve randomly modified the csaf.document.tracking.id and also added support for xz.
|
|
||
| Ok(()) | ||
| } | ||
| let response = user.post("/api/v2/advisory", file_bytes).await?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will upload the exact same file. Having multiple concurrent runners, the first one will be a real upload. The next one will be a no-op.
Wouldn't it make sense to insert some randomness into the content?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
test-data/advisories/.DS_Store
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this file
src/restapi.rs
Outdated
|
|
||
| /// Upload file and return advisory ID | ||
| pub async fn upload_advisory_and_get_id( | ||
| advisory_file: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you're only using a reference to this. If that's the case, please use &str and don't clone.
src/main.rs
Outdated
| if let Some(file) = &scenario.upload_advisory_files { | ||
| // Use sequential transaction execution to ensure immediate deletion after upload | ||
| s = s.register_transaction(tx!(upload_and_immediately_delete(file.clone(), advisory_files_counter.clone()),name: format!("upload_and_immediately_delete"))); | ||
| s = s.register_transaction(tx!(upload_and_immediately_delete(file.clone()),name: format!("upload_and_immediately_delete"))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is format! needed here?
src/restapi.rs
Outdated
| let (cached_path, content) = result; | ||
|
|
||
| // Verify that the cached path matches the requested path | ||
| if cached_path != file_path { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it makes more sense to have a "map" instead of failing here. Or maybe, instead of using a global static with a dynamic capture, load the file in the setup of the tests, and provide the loaded content directly.
|
Thank you, I think we are on the right track now. Just a few small things to iron out. |
668e969 to
66231c6
Compare
Updated, please check again. |
| .await | ||
| } | ||
| /// Load advisory files from UPLOAD_FILE_PATH directory, or fall back to CARGO_MANIFEST_DIR | ||
| fn load_advisory_files(&self) -> anyhow::Result<Vec<PathBuf>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This supposed to be a single file now, right? Why is this still a Vec?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method keeps a certain level of generality and, in here, simply takes the first file encountered.
I have added a new environment variable called UPLOAD_FILE_PATH, which is used to represent the path for all uploaded files.(default value is "./test-data").
I have made corresponding changes based on Jens's comment (#74 (comment)). However, there is still an issue: if the upload has not fully completed, the delete operation may return a 404 error.
First, we can tolerate a certain number of errors. Second, we can add a thread sleep between the two REST requests. However, adding thread sleep may affect the results.
The test results are as shown below:

since they distinguish between different requests, they can also be considered acceptable.