Skip to content

Bank Account (Unit Tests) #2406

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

Open
igakigongo opened this issue Mar 9, 2025 · 2 comments
Open

Bank Account (Unit Tests) #2406

igakigongo opened this issue Mar 9, 2025 · 2 comments

Comments

@igakigongo
Copy link

I am not sure if I am doing ti right, but the tests indicate that the cancellation token should be passed from a given source.

We received the following error when we ran your code:

BankAccountTests.cs(158,23): warning xUnit1051: Calls to methods which accept CancellationToken should use TestContext.Current.CancellationToken to allow test cancellation to be more responsive. (https://xunit.net/xunit.analyzers/rules/xUnit1051)

I am sure the test case with the Tasks is the one with the issue, as indicated by the error message.

csharp [Fact(Skip = "Remove this Skip property to run this test")] public async Task Can_handle_concurrent_transactions() { var account = new BankAccount(); account.Open(); for (int i = 0; i < 500; i++) { var tasks = new List<Task>(); tasks.Add(Task.Factory.StartNew(() => { for (int j = 0; j < 100; j++) { account.Deposit(1m); account.Withdraw(1m); } })); await Task.WhenAll(tasks.ToArray()); } Assert.Equal(0m, account.Balance); }

Copy link
Contributor

github-actions bot commented Mar 9, 2025

Hello. Thanks for opening an issue on Exercism 🙂

At Exercism we use our Community Forum, not GitHub issues, as the primary place for discussion. That allows maintainers and contributors from across Exercism's ecosystem to discuss your problems/ideas/suggestions without them having to subscribe to hundreds of repositories.

This issue will be automatically closed. Please use this link to copy your GitHub Issue into a new topic on the forum, where we look forward to chatting with you!

If you're interested in learning more about this auto-responder, please read this blog post.

@ErikSchierboom
Copy link
Member

Could you share your code please?

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

No branches or pull requests

2 participants