Roll a custom TestEnv and drop lazy_static#176
Roll a custom TestEnv and drop lazy_static#176luisschwab wants to merge 3 commits intobitcoindevkit:masterfrom
TestEnv and drop lazy_static#176Conversation
|
Need to pin some stuff... |
28bba06 to
4f5ee42
Compare
notmandatory
left a comment
There was a problem hiding this comment.
I ran this through my AI friend 🤖 and it found two issue and one nit that I think are worth mentioning. Otherwise very good improvement to the testing!
|
Concept ACK |
4f5ee42 to
8653954
Compare
|
Addressed Steve's review and added a |
|
Looks like your code is correctly setting the headers on the Builder for both the async and blocking clients, so no need for the unused |
The extra field is for the test only, will be handy to catch any regressioms when we switch to |
oleonardolima
left a comment
There was a problem hiding this comment.
Overall looks good! However, we shouldn't have the new field on AsyncClient, left an explanation how to properly test it in a comment below.
| fn wait_until_electrum_sees_block(&self) { | ||
| let _header = self.electrsd.client.block_headers_subscribe().unwrap(); | ||
| loop { | ||
| if self.electrsd.client.block_headers_pop().unwrap().is_some() { | ||
| break; | ||
| } | ||
| self.electrsd.trigger().unwrap(); | ||
| self.electrsd.client.ping().unwrap(); | ||
| std::thread::sleep(Duration::from_millis(500)); | ||
| } | ||
| } |
There was a problem hiding this comment.
You should keep the exponential backoff approach, instead of having a fixed delay.
There was a problem hiding this comment.
What is the rationale in keeping it? We only need to wait for electrum to index the block, and 500ms is a rounding error compared to the improvement in test time that this PR accomplished. It's unnecessary complexity, as I'm not touching client code in this PR.
There was a problem hiding this comment.
What is the rationale in keeping it? We only need to wait for electrum to index the block, and 500ms is a rounding error compared to the improvement in test time that this PR accomplished. It's unnecessary complexity, as I'm not touching client code in this PR.
Alright, the rationale is that it already handles any scenario: one that indexes it quickly with the minimum overhead of 64 ms, and any other ones that might take longer, without the fixed overhead of 500ms for every single one.
It doesn't really add much complexity and the code already exists, and it does not touches any client code, only the test module.
Also, with the new change you are checking for any new block, which might not be the expected height.
There was a problem hiding this comment.
I'm -0 on this, but the exponential backoff can be kept.
| /// Get a `Legacy` regtest address. | ||
| fn get_legacy_address(&self) -> Address { | ||
| Address::from_str("mvUsRD2pNeQQ8nZq8CDEx6fjVQsyzqyhVC") | ||
| .unwrap() | ||
| .assume_checked() | ||
| } |
There was a problem hiding this comment.
What's the rationale for having fixed addresses, instead o fetching one from the client. If it's required only for test_get_scripthash_stats they should probably constants under that test only.
There was a problem hiding this comment.
bitcoind would use an address as destination for change for another addresses transaction. This is why tests were flaky. I see no issue in hardcoding these, as we only want to check transaction count and balance for an arbitrary address; in turn we also save a bunch of calls to bitcoind by using this approach.
There was a problem hiding this comment.
bitcoindwould use an address as destination for change for another addresses transaction. This is why tests were flaky. I see no issue in hardcoding these, as we only want to check transaction count and balance for an arbitrary address; in turn we also save a bunch of calls tobitcoindby using this approach.
Which tests were flaky ?
It was flaky due to:
(i) The address issue you mentioned
(ii) The conflicting bitcoind usage ?
If was due to (i) it's probably an issue on the test setup itself. If it was due to (ii) it's basically solved by using the new TestEnv, isn't ?
There was a problem hiding this comment.
It was because of (ii). IIRC bitcoind would use the legacy address to send change when sending to the other 3, so we would get 2 transactions vs the expected 1 transaction.
8653954 to
5bdab27
Compare
|
I pushed 5bdab27 to address the test for HTTP headers, it does in such a way that asserts it in the final HTTP request. I wasn't able to do it following the approach I mentioned #176 (comment), because |
Implement a custom `TestEnv`, which is instantiated per-test and fixes the un-dropped `bitcoind` issue. This also allows running tests with more than 1 thread, since they no longer share `bitcoind` and `electrsd` instances. Also adds helpers to fetch externally sourced addresses, fixing the issue where `bitcoind`'s wallet would send change outputs to it's own wallet address, which would mess with `test_get_scripthash_stats`. The `test` recipe and CI job are updated to now use 16 threads.
- updates the `test_get_tx_with_http_header` to assert for expected HTTP headers in final request. - updates `setup_clients_with_headers` to expect custom `url`.
5bdab27 to
f6faee5
Compare
oleonardolima
left a comment
There was a problem hiding this comment.
cACK f6faee5
I applied a few changes regarding the MSRV and the HTTP headers test, it still needs addressing for the exponential backoff and addresses comments above.
Closes #149
Implement a custom
TestEnv, which is instantiated per-test and fixes the un-droppedbitcoindissue. This also allows running tests with more than 1 thread, since they no longer sharebitcoindandelectrsdinstances.Also adds helpers to fetch externally sourced addresses, fixing the issue where
bitcoind's wallet would send change outputs to it's own wallet address, which would mess withtest_get_scripthash_stats.The
testrecipe and CI job are updated to now use 16 threads.