Skip to content

Conversation

@bxf12315
Copy link
Contributor

@bxf12315 bxf12315 commented Oct 30, 2025

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:
Screenshot 2025-10-30 at 11 51 05
since they distinguish between different requests, they can also be considered acceptable.

@@ -0,0 +1,2 @@
[env]
CARGO_WORKSPACE_ROOT = { value = "", relative = true } No newline at end of file
Copy link
Contributor

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?

Copy link
Contributor Author

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?

@@ -0,0 +1,2 @@
[env]
CARGO_MANIFEST_DIR = { value = "", relative = true } No newline at end of file
Copy link
Contributor

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.

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"))
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would it be?

Copy link
Contributor Author

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| {
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

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

Copy link
Contributor Author

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?;
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

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,
Copy link
Contributor

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")));
Copy link
Contributor

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 {
Copy link
Contributor

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.

@ctron
Copy link
Contributor

ctron commented Nov 27, 2025

Thank you, I think we are on the right track now. Just a few small things to iron out.

@bxf12315 bxf12315 force-pushed the TC-3071-1 branch 2 times, most recently from 668e969 to 66231c6 Compare November 27, 2025 13:24
@bxf12315
Copy link
Contributor Author

Thank you, I think we are on the right track now. Just a few small things to iron out.

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>> {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants