Skip to content
Snippets Groups Projects

arti: Fix TODO: Add test for onion_proxy::build_list

Merged playbahn requested to merge playbahn/arti:todo1 into main
8 unresolved threads

Resolves a TODO mentioning the need for a test for arti::onion_proxy::build_list

Edited by playbahn

Merge request reports

Pipeline #264186 passed

Pipeline passed for a535c1b9 on playbahn:todo1

Merged by oparaopara 2 weeks ago (Apr 2, 2025 12:58am UTC)

Merge details

  • Changes merged into main with ebae86a9.
  • Did not delete the source branch.

Pipeline #264403 passed

Pipeline passed for ebae86a9 on main

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
392 /// builders, producing a `Vec` of the results.
393 ///
394 /// # Panics
395 ///
396 /// Will panic if any of the builders supplied are invalid.
397 macro_rules! build_all {
398 ($builders:expr) => (
399 $builders
400 .into_iter()
401 .map(|builder| builder.build().unwrap())
402 .collect::<Vec<_>>()
403 );
404 ($($builder:expr),+ $(,)?) => (
405 vec![ $($builder.build().unwrap()),+ ]
406 );
407 }
  • Comment on lines +370 to +407
    Maintainer

    Why are these macros? It looks like these would be simpler as just regular functions? Unless I'm missing something, I think these should all be regular functions.

  • Please register or sign in to reply
  • 391 /// Takes either a `Vec` or a comma-separated list of
    392 /// builders, producing a `Vec` of the results.
    393 ///
    394 /// # Panics
    395 ///
    396 /// Will panic if any of the builders supplied are invalid.
    397 macro_rules! build_all {
    398 ($builders:expr) => (
    399 $builders
    400 .into_iter()
    401 .map(|builder| builder.build().unwrap())
    402 .collect::<Vec<_>>()
    403 );
    404 ($($builder:expr),+ $(,)?) => (
    405 vec![ $($builder.build().unwrap()),+ ]
    406 );
  • 70 70 #[cfg(feature = "onion-service-service")]
    71 71 pub(crate) type OnionServiceProxyConfigMap = BTreeMap<HsNickname, OnionServiceProxyConfig>;
    72 72
    73 /// The serialized format of an OnionServiceProxyConfigListBuilder:
    74 /// a map from nickname to `OnionServiceConfigBuilder`
    73 /// The serialized format of an `OnionServiceProxyConfigMapBuilder`:
    74 /// a map from `HsNickname` to `OnionServiceConfigBuilder`
  • 407 }
    408
    409 #[test]
    410 fn fn_build_list() {
    411 let nick_1 = HsNickname::new("nick_1".to_string()).unwrap();
    412 let nick_2 = HsNickname::new("nick_2".to_string()).unwrap();
    413
    414 let proxy_configs = build_all![
    415 onion_service_proxy_config_builder!(nick_1),
    416 onion_service_proxy_config_builder!(nick_2),
    417 ];
    418 let actual = build_list(proxy_configs.clone());
    419
    420 assert!(actual.is_ok());
    421
    422 let actual = actual.unwrap();
    • Comment on lines +418 to +422
      Maintainer

      You can skip the assert!(actual.is_ok()) since the actual.unwrap() below will give us a better error message.

      But I think it's better to do this all as one line:

      let actual = build_list(proxy_configs.clone()).unwrap();

      And the same for the duplicate case below with is_err().

    • playbahn changed this line in version 2 of the diff

      changed this line in version 2 of the diff

    • Please register or sign in to reply
  • 402 .collect::<Vec<_>>()
    403 );
    404 ($($builder:expr),+ $(,)?) => (
    405 vec![ $($builder.build().unwrap()),+ ]
    406 );
    407 }
    408
    409 #[test]
    410 fn fn_build_list() {
    411 let nick_1 = HsNickname::new("nick_1".to_string()).unwrap();
    412 let nick_2 = HsNickname::new("nick_2".to_string()).unwrap();
    413
    414 let proxy_configs = build_all![
    415 onion_service_proxy_config_builder!(nick_1),
    416 onion_service_proxy_config_builder!(nick_2),
    417 ];
    • Comment on lines +414 to +417
      Maintainer

      I feel like this would be simpler as just the following, no helper macros/functions needed. It's about as short, and you don't need to look around at helper functions to know what it's doing.

      let proxy_configs: Vec<_> = [&nick_1, &nick_2].into_iter().map(|nick| {
          let mut builder = OnionServiceProxyConfigBuilder::default();
          builder.service().nickname(nick.clone());
          builder.build().unwrap()
      }).collect();

      And the same for the duplicate case below.

    • Author Contributor

      This is brilliant. I've got to follow KISS more.

    • playbahn changed this line in version 2 of the diff

      changed this line in version 2 of the diff

    • Please register or sign in to reply
  • opara
    opara @opara started a thread on the diff
  • 395 ///
    396 /// Will panic if any of the builders supplied are invalid.
    397 macro_rules! build_all {
    398 ($builders:expr) => (
    399 $builders
    400 .into_iter()
    401 .map(|builder| builder.build().unwrap())
    402 .collect::<Vec<_>>()
    403 );
    404 ($($builder:expr),+ $(,)?) => (
    405 vec![ $($builder.build().unwrap()),+ ]
    406 );
    407 }
    408
    409 #[test]
    410 fn fn_build_list() {
    • Comment on lines +409 to +410
      Maintainer

      Can you add a comment to this fn_build_list function explaining what it's testing? Something like "Testing [`build_list`] with and without duplicate service nicknames".

      Edited by opara
    • Please register or sign in to reply
  • 13 13 // part of the configuration was invalid.
    14 14 //
    15 15 // This is part of the public API.
    16 #[derive(Debug, Clone, thiserror::Error)]
    16 #[derive(Debug, Clone, thiserror::Error, PartialEq, Eq)]
    17 17 #[non_exhaustive]
    18 18 pub enum ConfigBuildError {
    • Comment on lines 8 to 18
      Maintainer

      I'm hesitant to derive PartialEq and Eq for ConfigBuildError, since it means that we can never put non-PartialEq types here in the future, and we only need this functionality for a test.

      Can you change fn_build_list to do something like:

      let ConfigBuildError::Inconsistent { fields, problem } = actual else {
          panic!("Unexpected error from `build_list`: {expected}");
      };
      
      assert_eq!(fields, vec!["nickname".to_string()]);
      assert_eq!(problem, format!("Multiple onion services with the nickname {nick_dup}"));

      and remove the PartialEq, Eq here?

      Edited by opara
    • Please register or sign in to reply
  • Maintainer

    Thanks for adding the test! I have a few comments, but otherwise looks good.

  • opara requested changes

    requested changes

  • playbahn added 1 commit

    added 1 commit

    • ec674740 - arti: Fix TODO: Rework test: onion_proxy::build_list

    Compare with previous version

  • Author Contributor

    All done.

  • playbahn marked this merge request as draft

    marked this merge request as draft

  • playbahn marked this merge request as ready

    marked this merge request as ready

  • opara approved this merge request

    approved this merge request

    • Maintainer

      Looks good, thanks! Now we just need to fight with the CI until it passes. The failures all seem to be "ERROR: Job failed: failed to pull image [...]", so hopefully if we restart it enough times it will pass.

    • Author Contributor

      I'm afraid the maint-check-cbindgen test job won't pass, !2901 (merged) fixes this, but it was merged after I opened this MR, so I don't have those changes on branch todo1. LMK if I should update my local branch.

      if we restart it enough times it will pass

      I tried quite a few times hours ago then just gave up :(

    • Maintainer

      I'm afraid the maint-check-cbindgen test job won't pass, !2901 (merged) fixes this, but it was merged after I opened this MR, so I don't have those changes on branch todo1. LMK if I should update my local branch.

      Okay, yeah please rebase this MR on the latest changes on main then, and then force push here. If you have any questions about this lmk.

      if we restart it enough times it will pass

      I tried quite a few times hours ago then just gave up :(

      Yeah, it's painful. I'll take care of restarting the jobs to make sure they run.

    • Author Contributor

      Rebased and pushed. Latest commit from main in todo1 is now 8f85ef297dfff71ad586b7784a39ea25a133505b

      Edited by playbahn
    • Maintainer

      if we restart it enough times it will pass

      I tried quite a few times hours ago then just gave up :(

      I think what's happening here is that the proxy is trying to download the container image from Dockerhub, but has reached its rate limit. It might take a few hours for the rate limit to reset.

    • Please register or sign in to reply
  • playbahn added 29 commits

    added 29 commits

    • ec674740...8f85ef29 - 27 commits from branch tpo/core:main
    • b70fc14b - arti: onion_proxy::build_list: fix TODO: Add test
    • a535c1b9 - arti: Fix TODO: Rework test: onion_proxy::build_list

    Compare with previous version

  • Author Contributor

    CI is green!

  • opara mentioned in commit ebae86a9

    mentioned in commit ebae86a9

  • merged

  • Please register or sign in to reply
    Loading