Skip to content

Permanent Fix for Flaky Unit Test #1690

Closed
@chayim

Description

@chayim

The test_alias unit test for RediSearch has some behaviour that is randomly flaky, specifically with the alias updates. PRs constantly randomly fail because of this. So far, we've attempted to solve these issues by adding sleeps that are specific to GitHub runners, but that isn't correct.

    @pytest.mark.redismod
    @skip_ifmodversion_lt("2.0.0", "search")
    def test_alias():
        index1 = getClient()
        index2 = getClient()
    
        index1.hset("index1:lonestar", mapping={"name": "lonestar"})
        index2.hset("index2:yogurt", mapping={"name": "yogurt"})
    
        if os.environ.get("GITHUB_WORKFLOW", None) is not None:
            time.sleep(2)
        else:
            time.sleep(5)
    
        def1 = IndexDefinition(prefix=["index1:"], score_field="name")
        def2 = IndexDefinition(prefix=["index2:"], score_field="name")
    
        ftindex1 = index1.ft("testAlias")
        ftindex2 = index1.ft("testAlias2")
        ftindex1.create_index((TextField("name"),), definition=def1)
        ftindex2.create_index((TextField("name"),), definition=def2)
    
        # CI is slower
        try:
            res = ftindex1.search("*").docs[0]
        except IndexError:
            time.sleep(5)
            res = ftindex1.search("*").docs[0]
        assert "index1:lonestar" == res.id
    
        # create alias and check for results
        ftindex1.aliasadd("spaceballs")
        alias_client = getClient().ft("spaceballs")
        res = alias_client.search("*").docs[0]
        assert "index1:lonestar" == res.id
    
        # Throw an exception when trying to add an alias that already exists
        with pytest.raises(Exception):
            ftindex2.aliasadd("spaceballs")
    
        # update alias and ensure new results
        ftindex2.aliasupdate("spaceballs")
        alias_client2 = getClient().ft("spaceballs")
    
        if os.environ.get("GITHUB_WORKFLOW", None) is not None:
            time.sleep(5)
    
>       res = alias_client2.search("*").docs[0]
E       IndexError: list index out of range

Metadata

Metadata

Assignees

No one assigned

    Labels

    maintenanceMaintenance (CI, Releases, etc)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions