Skip to content

Commit 14b0a01

Browse files
committed
Increase default stack size to 16, and use enable_time and enable_io
1 parent ac7e4a6 commit 14b0a01

4 files changed

Lines changed: 62 additions & 56 deletions

File tree

src/fungi/meta.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,31 @@ use crate::store;
1212

1313
const ID_LEN: usize = 32;
1414
const KEY_LEN: usize = 32;
15-
const TYPE_MASK: u32 = libc::S_IFMT;
15+
const TYPE_MASK: u32 = libc::S_IFMT as u32;
1616

1717
#[repr(u32)]
1818
#[derive(Debug, Clone, PartialEq, Eq)]
1919
pub enum FileType {
20-
Regular = libc::S_IFREG,
21-
Dir = libc::S_IFDIR,
22-
Link = libc::S_IFLNK,
23-
Block = libc::S_IFBLK,
24-
Char = libc::S_IFCHR,
25-
Socket = libc::S_IFSOCK,
26-
FIFO = libc::S_IFIFO,
20+
Regular = libc::S_IFREG as u32,
21+
Dir = libc::S_IFDIR as u32,
22+
Link = libc::S_IFLNK as u32,
23+
Block = libc::S_IFBLK as u32,
24+
Char = libc::S_IFCHR as u32,
25+
Socket = libc::S_IFSOCK as u32,
26+
FIFO = libc::S_IFIFO as u32,
2727
Unknown = 0xFFFFFFFF, // Use a different value to avoid conflict
2828
}
2929

3030
impl From<u32> for FileType {
3131
fn from(value: u32) -> Self {
3232
match value {
33-
libc::S_IFREG => Self::Regular,
34-
libc::S_IFDIR => Self::Dir,
35-
libc::S_IFLNK => Self::Link,
36-
libc::S_IFBLK => Self::Block,
37-
libc::S_IFCHR => Self::Char,
38-
libc::S_IFSOCK => Self::Socket,
39-
libc::S_IFIFO => Self::FIFO,
33+
x if x == libc::S_IFREG as u32 => Self::Regular,
34+
x if x == libc::S_IFDIR as u32 => Self::Dir,
35+
x if x == libc::S_IFLNK as u32 => Self::Link,
36+
x if x == libc::S_IFBLK as u32 => Self::Block,
37+
x if x == libc::S_IFCHR as u32 => Self::Char,
38+
x if x == libc::S_IFSOCK as u32 => Self::Socket,
39+
x if x == libc::S_IFIFO as u32 => Self::FIFO,
4040
_ => Self::Unknown,
4141
}
4242
}

src/server/block_handlers.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,10 @@ pub async fn upload_block_handler(
6666

6767
// Get the username from the extension (set by the authorize middleware)
6868
let username = extension.0;
69-
if username.is_empty() {
69+
if username.is_empty() {
7070
log::error!("Username is required but not provided");
71-
return Err(ResponseError::BadRequest(
72-
"Username is required".to_string(),
73-
));
74-
}
71+
return Err(ResponseError::BadRequest("Username is required".to_string()));
72+
}
7573
let user_id = auth::get_user_id_from_token(&*state.db, &username).await?;
7674

7775
// Store the block data in the database
@@ -431,9 +429,7 @@ pub async fn get_user_blocks_handler(
431429
let username = extension.0;
432430
if username.is_empty() {
433431
log::error!("Username is required but not provided");
434-
return Err(ResponseError::BadRequest(
435-
"Username is required".to_string(),
436-
));
432+
return Err(ResponseError::BadRequest("Username is required".to_string()));
437433
}
438434
let user_id = auth::get_user_id_from_token(&*state.db, &username).await?;
439435

src/server/file_handlers.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ pub async fn upload_file_handler(
6262
let username = extension.0;
6363
if username.is_empty() {
6464
log::error!("Username is required but not provided");
65-
return Err(ResponseError::BadRequest(
66-
"Username is required".to_string(),
67-
));
65+
return Err(ResponseError::BadRequest("Username is required".to_string()));
6866
}
6967
let user_id = auth::get_user_id_from_token(&*state.db, &username).await?;
7068

tests/docker_test.rs

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ mod docker_tests {
33
use anyhow::Result;
44
use std::path::Path;
55
use tempdir::TempDir;
6-
use tokio::runtime::Runtime;
76
use uuid::Uuid;
87

98
use rfs::fungi;
10-
use rfs::store::{self, dir::DirStore};
9+
use rfs::store::dir::DirStore;
1110
use rfs::DockerImageToFlist;
1211

1312
#[test]
@@ -18,42 +17,55 @@ mod docker_tests {
1817
return Ok(());
1918
}
2019

21-
// Create a runtime for async operations
22-
let rt = Runtime::new()?;
20+
// Run the test on a thread with larger stack size to avoid stack overflow
21+
let handle = std::thread::Builder::new()
22+
.stack_size(16 * 1024 * 1024) // 16MB stack size
23+
.spawn(move || -> Result<()> {
24+
// Create a custom runtime with timers and IO enabled
25+
let rt = tokio::runtime::Builder::new_multi_thread()
26+
.worker_threads(2)
27+
.enable_time()
28+
.enable_io()
29+
.build()
30+
.unwrap();
2331

24-
rt.block_on(async {
25-
// Create temporary directories
26-
let temp_dir = TempDir::new("docker-test")?;
27-
let store_dir = temp_dir.path().join("store");
28-
std::fs::create_dir_all(&store_dir)?;
32+
rt.block_on(async {
33+
// Create temporary directories
34+
let temp_dir = TempDir::new("docker-test")?;
35+
let store_dir = temp_dir.path().join("store");
36+
std::fs::create_dir_all(&store_dir)?;
2937

30-
// Create a store
31-
let store = DirStore::new(&store_dir).await?;
38+
// Create a store
39+
let store = DirStore::new(&store_dir).await?;
3240

33-
// Create a flist writer
34-
let fl_path = temp_dir.path().join("alpine-test.fl");
35-
let meta = fungi::Writer::new(&fl_path, true).await?;
41+
// Create a flist writer
42+
let fl_path = temp_dir.path().join("alpine-test.fl");
43+
let meta = fungi::Writer::new(&fl_path, true).await?;
3644

37-
// Create a temporary directory for docker extraction
38-
let container_name = Uuid::new_v4().to_string();
39-
let docker_tmp_dir = TempDir::new(&container_name)?;
45+
// Create a temporary directory for docker extraction
46+
let container_name = Uuid::new_v4().to_string();
47+
let docker_tmp_dir = TempDir::new(&container_name)?;
4048

41-
// Create DockerImageToFlist instance
42-
let mut docker_to_fl = DockerImageToFlist::new(
43-
meta,
44-
"alpine:latest".to_string(),
45-
None, // No credentials for public image
46-
docker_tmp_dir,
47-
);
49+
// Create DockerImageToFlist instance
50+
let mut docker_to_fl = DockerImageToFlist::new(
51+
meta,
52+
"alpine:latest".to_string(),
53+
None, // No credentials for public image
54+
docker_tmp_dir,
55+
);
4856

49-
// Convert docker image to flist
50-
docker_to_fl.convert(store, None).await?;
57+
// Convert docker image to flist
58+
docker_to_fl.convert(store, None).await?;
5159

52-
// Verify the flist was created
53-
assert!(Path::new(&fl_path).exists(), "Flist file was not created");
60+
// Verify the flist was created
61+
assert!(Path::new(&fl_path).exists(), "Flist file was not created");
5462

55-
Ok(())
56-
})
63+
Ok(())
64+
})
65+
})
66+
.unwrap();
67+
68+
handle.join().unwrap()
5769
}
5870

5971
// Helper function to check if docker is available

0 commit comments

Comments
 (0)