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

YList test fails when list entity added before keys are initialized #800

Closed
ygorelik opened this issue Jun 14, 2018 · 2 comments
Closed
Assignees

Comments

@ygorelik
Copy link
Collaborator

Current Behavior

YList functionality fails when list entity key values initialized after the element is added to the list.

Root cause
It is happening because by the time of appending to the list the key values are not yet set. That causes the entity to be stored in the YList map with wrong key value.

Steps to Reproduce

Run this C++ test:

TEST_CASE("test_ylist_race")
{
	TestEntity* list_holder = new TestEntity();

    YList ylist = YList(list_holder, {"name"});

    // Append test1 to the YList before key value is defined
    auto test1 = std::make_shared<TestEntity>();
    ylist.append(test1);

    test1->name = "test1";
    test1->enabled = true;

    auto keys = ylist.keys();
    REQUIRE(vector_to_string(keys) == R"("test1")");

    auto ep = ylist["test1"];
    REQUIRE(ep != nullptr);
}

The test fails with message:

/home/yan/ydk-workspace/ydk-gen/sdk/cpp/core/tests/test_entity.cpp:452: FAILED:
  REQUIRE( vector_to_string(keys) == R"("test1")" )
with expansion:
  ""0"" == ""test1""

Expected Behavior

The test should pass as long as list element keys are initialized before any access to the list.

System Information

YDK0.7.2

@ygorelik ygorelik self-assigned this Jun 14, 2018
@ygorelik
Copy link
Collaborator Author

Solution for this issue should be similar to the one applied in Python (append entities to cache, then flush the cache to YList map before accessing it), but it breaks 'const' qualifier in multiple Entity class functions in the generated bundle code. That will affect lots of core and generated code. Hence postponing the resolution of this bug to the next release.

@ygorelik ygorelik removed their assignment Jan 30, 2019
ygorelik pushed a commit to ygorelik/ydk-gen that referenced this issue Jul 22, 2019
@ygorelik
Copy link
Collaborator Author

Fixed with this commit to 0.8.4 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant