Skip to content
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

Overhaul core Tracker: refactor tests (remove duplicate code) #1198

Closed
Tracked by #1181
josecelano opened this issue Jan 22, 2025 · 0 comments · Fixed by #1200
Closed
Tracked by #1181

Overhaul core Tracker: refactor tests (remove duplicate code) #1198

josecelano opened this issue Jan 22, 2025 · 0 comments · Fixed by #1200
Assignees
Labels
Code Cleanup / Refactoring Tidying and Making Neat

Comments

@josecelano
Copy link
Member

josecelano commented Jan 22, 2025

Parent issue: #1181

The following code code is repeated many times in tests. It's the initialization of the application services.

let cfg = Arc::new(ephemeral_public());
let config = &cfg.http_api.clone().unwrap();

let ban_service = Arc::new(RwLock::new(BanService::new(MAX_CONNECTION_ID_ERRORS_PER_IP)));
let (stats_event_sender, stats_repository) = statistics::setup::factory(cfg.core.tracker_usage_statistics);
let stats_event_sender = Arc::new(stats_event_sender);
let stats_repository = Arc::new(stats_repository);

initialize_global_services(&cfg);

let database = initialize_database(&cfg);
let in_memory_whitelist = Arc::new(InMemoryWhitelist::default());
let whitelist_authorization = Arc::new(whitelist::authorization::Authorization::new(
    &cfg.core,
    &in_memory_whitelist.clone(),
));
let whitelist_manager = initialize_whitelist_manager(database.clone(), in_memory_whitelist.clone());
let db_key_repository = Arc::new(DatabaseKeyRepository::new(&database));
let in_memory_key_repository = Arc::new(InMemoryKeyRepository::default());
let _authentication_service = Arc::new(service::AuthenticationService::new(&cfg.core, &in_memory_key_repository));
let keys_handler = Arc::new(KeysHandler::new(
    &db_key_repository.clone(),
    &in_memory_key_repository.clone(),
));
let authentication = Arc::new(authentication::Facade::new(&keys_handler));

let tracker = Arc::new(initialize_tracker(&cfg, &database, &whitelist_authorization, &authentication));

We now have the AppContainer and it's initialized here.

The initialization is not exactly the same in all tests because in some tests some services are not needed or mocked. However I think we can extract a simple abstraction or even a builder in the future. For now, I'm just going to remove the duplication as much as possible.

@josecelano josecelano added the Code Cleanup / Refactoring Tidying and Making Neat label Jan 22, 2025
@josecelano josecelano self-assigned this Jan 22, 2025
@josecelano josecelano mentioned this issue Jan 22, 2025
26 tasks
josecelano added a commit to josecelano/torrust-tracker that referenced this issue Jan 22, 2025
josecelano added a commit to josecelano/torrust-tracker that referenced this issue Jan 22, 2025
josecelano added a commit that referenced this issue Jan 22, 2025
…tests

df6ed93 refactor: [#1198] remove duplicate code in app init in tests (Jose Celano)

Pull request description:

  Remove duplicate code for application initialization in tests.

ACKs for top commit:
  josecelano:
    ACK df6ed93

Tree-SHA512: 51cdb91da53e9bb22aeb2724494b111e79f1c3e9db7bbd13dc0558e5bffd677a61faac771ae365f3cebcd689658f8df3821e2a95430a2c2b01d3471f1094bf8b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Cleanup / Refactoring Tidying and Making Neat
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant