Skip to content

Commit

Permalink
[eclipse-iceoryx#361] Add timeout test for zero copy connection
Browse files Browse the repository at this point in the history
  • Loading branch information
elfenpiff committed Aug 30, 2024
1 parent 7e92e45 commit 07490a1
Showing 1 changed file with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) 2024 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available under the
// terms of the Apache Software License 2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
// which is available at https://opensource.org/licenses/MIT.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT

mod zero_copy_connection_posix_shared_memory_tests {
use iceoryx2_bb_elementary::math::ToB64;
use iceoryx2_bb_posix::creation_mode::CreationMode;
use iceoryx2_bb_posix::permission::Permission;
use iceoryx2_bb_posix::unique_system_id::UniqueSystemId;
use iceoryx2_bb_system_types::file_name::*;
use iceoryx2_bb_testing::assert_that;
use iceoryx2_cal::named_concept::*;
use iceoryx2_cal::zero_copy_connection::*;
use std::time::Duration;

const TIMEOUT: Duration = Duration::from_millis(100);

fn generate_name() -> FileName {
let mut file = FileName::new(b"test_").unwrap();
file.push_bytes(UniqueSystemId::new().unwrap().value().to_b64().as_bytes())
.unwrap();
file
}

#[test]
fn waiting_for_initialization_works() {
type Sut = iceoryx2_cal::zero_copy_connection::posix_shared_memory::Connection;
let storage_name = generate_name();
let file_name = <Sut as NamedConceptMgmt>::Configuration::default()
.path_for(&storage_name)
.file_name();

let _raw_shm = iceoryx2_bb_posix::shared_memory::SharedMemoryBuilder::new(&file_name)
.creation_mode(CreationMode::PurgeAndCreate)
.size(1234)
.has_ownership(true)
.permission(Permission::OWNER_WRITE)
.create()
.unwrap();

let start = std::time::SystemTime::now();
let sut = <Sut as ZeroCopyConnection>::Builder::new(&storage_name)
.timeout(TIMEOUT)
.create_sender(1);

assert_that!(start.elapsed().unwrap(), ge TIMEOUT);
assert_that!(sut, is_err);
assert_that!(sut.err().unwrap(), eq ZeroCopyCreationError::InitializationNotYetFinalized);
}
}

0 comments on commit 07490a1

Please sign in to comment.