<commit_before>#include "utils/async_if_test_helper.hxx"

#include "nmranet/NMRAnetWriteFlow.hxx"
#include "nmranet/NMRAnetAsyncDefaultNode.hxx"

namespace NMRAnet
{

TEST_F(AsyncIfTest, CreateNodeSendsInitializer)
{
    //expect_packet(":X1070122AN02010d000003"); // AMD frame
    expect_packet(":X1910022AN02010d000003;"); // initialization complete
    //create_allocated_alias();
    LOG(INFO, "before");
    DefaultAsyncNode node(ifCan_.get(), TEST_NODE_ID);
    // Technically there is a race condition here. The initialization could
    // happen before we get to this expectation.
    EXPECT_FALSE(node.is_initialized());
    ifCan_->add_addressed_message_support();
    LOG(INFO, "after");
    wait();
    EXPECT_TRUE(node.is_initialized());
    EXPECT_EQ(&node, ifCan_->lookup_local_node(TEST_NODE_ID));
}

TEST_F(AsyncIfTest, TwoNodesInitialize)
{
    ifCan_->add_addressed_message_support();
    expect_packet(":X1910022AN02010d000003;"); // initialization complete
    create_allocated_alias();
    LOG(INFO, "before");
    DefaultAsyncNode node(ifCan_.get(), TEST_NODE_ID);
    LOG(INFO, "after");
    wait();
    expect_packet(":X1070133AN02010d000004;"); // AMD frame
    expect_packet(":X1910033AN02010d000004;"); // initialization complete<commit_msg>Fixes flakiness in async node test.<commit_after>#include "utils/async_if_test_helper.hxx"

#include "nmranet/NMRAnetWriteFlow.hxx"
#include "nmranet/NMRAnetAsyncDefaultNode.hxx"

namespace NMRAnet
{

TEST_F(AsyncIfTest, CreateNodeSendsInitializer)
{
    //expect_packet(":X1070122AN02010d000003"); // AMD frame
    expect_packet(":X1910022AN02010d000003;"); // initialization complete
    //create_allocated_alias();
    LOG(INFO, "before");
    BlockExecutor block(nullptr);
    DefaultAsyncNode node(ifCan_.get(), TEST_NODE_ID);
    // Technically there is a race condition here. The initialization could
    // happen before we get to this expectation.
    EXPECT_FALSE(node.is_initialized());
    block.release_block();
    ifCan_->add_addressed_message_support();
    LOG(INFO, "after");
    wait();
    EXPECT_TRUE(node.is_initialized());
    EXPECT_EQ(&node, ifCan_->lookup_local_node(TEST_NODE_ID));
}

TEST_F(AsyncIfTest, TwoNodesInitialize)
{
    ifCan_->add_addressed_message_support();
    expect_packet(":X1910022AN02010d000003;"); // initialization complete
    create_allocated_alias();
    LOG(INFO, "before");
    DefaultAsyncNode node(ifCan_.get(), TEST_NODE_ID);
    LOG(INFO, "after");
    wait();
    expect_packet(":X1070133AN02010d000004;"); // AMD frame
    expect_packet(":X1910033AN02010d000004;"); // initialization complete
{'fraction_non_alphanumeric': 0.12743227775658145, 'fraction_numerical': 0.0686760778328882, 'mean_word_length': 5.169411764705882, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6175684', 'n_tokens_mistral': 967, 'n_tokens_neox': 867, 'n_words': 143}