Skip to content

Fix API bug: Torrent cannot be whitelisted twice#117

Merged
da2ce7 merged 9 commits intodevelopfrom
issue-74-fix-api-response-for-duplicate-whitelist-requests
Nov 25, 2022
Merged

Fix API bug: Torrent cannot be whitelisted twice#117
da2ce7 merged 9 commits intodevelopfrom
issue-74-fix-api-response-for-duplicate-whitelist-requests

Conversation

@josecelano
Copy link
Copy Markdown
Member

@josecelano josecelano commented Nov 24, 2022

  • Reproduce the error with an e2e test.
  • Fix it.
  • Rename test to should_allow_to_whitelist_a_torrent
  • Refactor: extract function is_info_hash_whitelisted as described here.

The API endpoint to whitelist torrents returns an error if you try to
whitelist the same torrent twice. This test reproduces that wrong
behavior before fixing it.
@da2ce7 da2ce7 added the Bug Incorrect Behavior label Nov 24, 2022
@josecelano josecelano marked this pull request as ready for review November 24, 2022 18:58
@josecelano
Copy link
Copy Markdown
Member Author

ACK 2d621c5

Copy link
Copy Markdown
Contributor

@da2ce7 da2ce7 left a comment

Choose a reason for hiding this comment

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

You seem to be just checking if there is any error, then assuming that it isn't already inserted.

I suggest that you consider: #118

… errors

167b749 db: check info_hash record not found instead dropping all errors (Cameron Garnham)

Pull request description:

ACKs for top commit:
  josecelano:
    ACK 167b749

Tree-SHA512: 432a64371b0cc425ef21248c5fb7334257db30e6b52e8e0bebcb02291441523f1bddefe0780cd79693fe5e1cf26d3cf528d1b4e6d3eeebada32e108a2844aaa1
@josecelano josecelano marked this pull request as draft November 24, 2022 21:36
In the e2e tests we needed to wait until the API server is ready to
accept request. We were waiting a random duration (100 milliseconds).

Now we send a message from the API when is ready to the initiator.

In production code is not used.
@josecelano
Copy link
Copy Markdown
Member Author

hi @da2ce7 @WarmBeer, I changed the implementation to send a message from the API server to the initiator when the API is ready, as we discussed yesterday. You can see the changes here.

I do not like it yet. I think we should send the message after starting the server.

I think we can do what @da2ce7 suggested. Something like:

tokio::spawn(async move {
    let (_addr, api_server) = serve(server).bind_with_graceful_shutdown(socket_addr, async move {
        tokio::signal::ctrl_c().await.expect("Failed to listen to shutdown signal.");
    });
});

// Send a message to the initiator to notify the API is ready to accept requests
if messenger_to_initiator.send(ApiReady()).is_err() {
    panic!("the receiver dropped");
}

@da2ce7 is that what you suggested? Using a new thread to launch the server and send the message afterwards.

I'm not sure if that's a significant change. I suppose the problem was not the time it takes the server to be ready but the fact that tests run in parallel.

There are two main changes:

- The API server does not send the message when is ready. The job
  starter waits until the API server is running. This change is less
  radical becuase we keep the `start_job` return type as the other job
  starters. We did not want to send a real message from the API. We only
  wanted to know that the API thread is up and running.
- The job starter waits until the API job is running even in production
  code. In the previous version we did that only for the e2e tests.
@josecelano josecelano marked this pull request as ready for review November 25, 2022 14:14
@josecelano
Copy link
Copy Markdown
Member Author

ACK 15aa831

Cameron Garnham (@da2ce7) suggested this change. It's better to send the
event after spwaning the API server task.
@josecelano
Copy link
Copy Markdown
Member Author

ACK 5274b2c

Copy link
Copy Markdown
Contributor

@da2ce7 da2ce7 left a comment

Choose a reason for hiding this comment

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

ACK 5274b2c

@da2ce7 da2ce7 merged commit 8ac31a9 into develop Nov 25, 2022
@josecelano josecelano deleted the issue-74-fix-api-response-for-duplicate-whitelist-requests branch December 1, 2022 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Incorrect Behavior

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Tracker API should return an OK status when whitelisting an already whitelisted info hash

2 participants