Skip to content

Conversation

@michaeldjeffrey
Copy link
Contributor

Provide a testing FileSink that acks messages as they're written so we don't have to deal with race conditions in tests.

Previously

    let (_, rewards) = tokio::join!(
        rewarder::reward_mappers(&pool, &mobile_rewards_client, &reward_info),
        receive_expected_rewards(&mut mobile_rewards)
    );

Tests required that you know how many messages you were expecting, otherwise the test would hang indefinitely either waiting for a written message to be acknowledged, or waiting for a message that would never be written.

Now

The test FileSinkReceiver consumes all messages that are written as they come.
Functions in the rewarder now own a FileSinkClient<T>

pub async fn reward_poc_and_dc(
    pool: &Pool<Postgres>,
    hex_service_client: &impl HexBoostingInfoResolver<Error = ClientError>,
    mobile_rewards: FileSinkClient<proto::MobileRewardShare>,
    speedtest_avg_sink: &FileSinkClient<proto::SpeedtestAvg>,
    reward_info: &EpochRewardInfo,
    price_info: PriceInfo,
)

Cloning a FileSinkClient<T> is relatively cheap as it's just a channel and a metrics string.
When the rewarding function under test is done, it will drop the Sender, and we can know that all messages that will be written have been written.

We can then make assertions against all the messages written during the test. Whether they were expected or not.

Tests where the values were different were testing percentages rather than anything specific to EpochRewardInfo.
- reward_poc_dc now takes a FileSinkClient non reference so it will drop when rewarding is done.
- Add AsPubkeyMap trait for converting Vec<T> to a PublicKeyBinary HashMap.
add wait until written for speedtest avgs
unallocated is kept as a vec even though there should only be one out of convenience of implementation. And in the case where a rewarder can output multiple types of unallocated for a single message type.
@michaeldjeffrey michaeldjeffrey merged commit 8cc5ffa into main Apr 14, 2025
27 checks passed
@michaeldjeffrey michaeldjeffrey deleted the mj/nonblocking-rewards-sink branch April 14, 2025 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants