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

Introduce SkipUtils and Refactor Skip Logic #7

Open
Atralupus opened this issue Nov 20, 2024 · 0 comments
Open

Introduce SkipUtils and Refactor Skip Logic #7

Atralupus opened this issue Nov 20, 2024 · 0 comments

Comments

@Atralupus
Copy link
Member

Atralupus commented Nov 20, 2024

Many tests currently use repetitive logic to skip tests with Assert.Skip. To improve maintainability and reduce redundancy, a utility method SkipUtils.ExecuteWithSkipAsync should be introduced and applied across the codebase.

Implementation Example:

namespace MimirUptime;

public static class SkipUtils
{
    public static async Task<T> ExecuteWithSkipAsync<T>(
        Func<Task<T>> requestFunc,
        string skipMessage
    )
    {
        try
        {
            return await requestFunc();
        }
        catch (Exception)
        {
            Assert.Skip(skipMessage);
            throw;
        }
    }
}

Application Example:

public async Task<int> GetHeadlessActionPointData(long blockIndex, Address avatarAddress)
{
    var stateResponse = await SkipUtils.ExecuteWithSkipAsync(
        async () => await headlessClient.GetState.ExecuteAsync(
            Addresses.ActionPoint.ToString(),
            avatarAddress.ToString(),
            blockIndex
        ),
        "Headless client is unresponsive; skipping test."
    );
    var result = CodecUtil.DecodeState(stateResponse.Data.State);
    
    if (result is not Integer value)
        throw new Exception();

    return value;
}

Refactor all relevant tests to use this utility method.

@Atralupus Atralupus changed the title Introduce SkipUtils and Refactor Skip Logic Across Tests Introduce SkipUtils and Refactor Skip Logic Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No Assignee
Development

No branches or pull requests

1 participant