Skip to content

Commit 67f2c19

Browse files
Fix bank account ineffective concurrency test (#2473)
* Fix bank account ineffective concurrency test * Fix path to configlet * Upgrade Scriban package * Fix warning --------- Co-authored-by: Erik Schierboom <erik_schierboom@hotmail.com>
1 parent 7be5989 commit 67f2c19

6 files changed

Lines changed: 14 additions & 14 deletions

File tree

bin/update-exercises.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ $PSNativeCommandUseErrorActionPreference = $true
2424
& bin/fetch-configlet
2525

2626
if ($Exercise) {
27-
& configlet sync --docs --metadata --filepaths --update --yes --exercise $Exercise
27+
& bin/configlet sync --docs --metadata --filepaths --update --yes --exercise $Exercise
2828
& dotnet run --project generators update --exercise $Exercise
2929
} else {
30-
& configlet sync --docs --metadata --filepaths --update --yes
30+
& bin/configlet sync --docs --metadata --filepaths --update --yes
3131
& dotnet run --project generators update
3232
}

exercises/practice/bank-account/.meta/Generator.tpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public class {{ testClass }}
3333
Assert.Equal({{ test.expected }}m, account.{{ op | to_call }});
3434
{{ end -}}
3535
{{- else if op.operation == "concurrent" }}
36+
var tasks = new List<Task>();
3637
for (int i = 0; i < 500; i++)
3738
{
38-
var tasks = new List<Task>();
3939
tasks.Add(Task.Factory.StartNew(() =>
4040
{
4141
for (int j = 0; j < 100; j++)
@@ -44,9 +44,9 @@ public class {{ testClass }}
4444
account.{{ nested_op | to_call }};
4545
{{- end -}}
4646
}
47-
}));
48-
await Task.WhenAll(tasks.ToArray());
47+
}, TestContext.Current.CancellationToken));
4948
}
49+
await Task.WhenAll(tasks.ToArray());
5050
{{- else }}
5151
account.{{ op | to_call }};
5252
{{- end -}}

exercises/practice/bank-account/BankAccountTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ public async Task Can_handle_concurrent_transactions()
152152
{
153153
var account = new BankAccount();
154154
account.Open();
155+
var tasks = new List<Task>();
155156
for (int i = 0; i < 500; i++)
156157
{
157-
var tasks = new List<Task>();
158158
tasks.Add(Task.Factory.StartNew(() =>
159159
{
160160
for (int j = 0; j < 100; j++)
@@ -163,8 +163,8 @@ public async Task Can_handle_concurrent_transactions()
163163
account.Withdraw(1m);
164164
}
165165
}, TestContext.Current.CancellationToken));
166-
await Task.WhenAll(tasks.ToArray());
167166
}
167+
await Task.WhenAll(tasks.ToArray());
168168
Assert.Equal(0m, account.Balance);
169169
}
170170
}

generators/Generators.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<PackageReference Include="Humanizer.Core" Version="3.0.10" />
1515
<PackageReference Include="LibGit2Sharp" Version="0.31.0" />
1616
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="5.3.0" />
17-
<PackageReference Include="Scriban" Version="6.5.5" />
17+
<PackageReference Include="Scriban" Version="7.0.6" />
1818
<PackageReference Include="Tomlyn" Version="1.1.1" />
1919
</ItemGroup>
2020

generators/Templates.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static string RenderTestsCode(CanonicalData canonicalData)
1818
scriptObject.Import("enum", new Func<string, string, string>((text, enumType) =>
1919
$"{enumType.Pascalize()}.{text.Pascalize()}"));
2020
scriptObject.Import("property", new Func<ScriptArray, string, ScriptArray>((testCases, name) =>
21-
new ScriptArray(testCases.Cast<ScriptObject>().Where(testCase => testCase["property"].ToString() == name))));
21+
new ScriptArray(testCases.Cast<ScriptObject>().Where(testCase => testCase["property"]?.ToString() == name))));
2222
scriptObject.Import(TemplateData.ForCanonicalData(canonicalData));
2323

2424
var context = new TemplateContext();

generators/packages.lock.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
},
4040
"Scriban": {
4141
"type": "Direct",
42-
"requested": "[6.5.5, )",
43-
"resolved": "6.5.5",
44-
"contentHash": "TxsmDVQ9agPQaY+SvdTO+zntGpJOnL1QaO4dzACfc6gEKRYhoMpzCCFuVixEZXet291sRnjyym6lB69Cr/EXPQ=="
42+
"requested": "[7.0.6, )",
43+
"resolved": "7.0.6",
44+
"contentHash": "bOtHyk30sjl0y3+KYImIJv0ETZYLuFFJvlBF2ks2YLNtydhJqxRTGe4WaBDvg/3VRhhI6uf+qVfixuFROsOi+w=="
4545
},
4646
"Tomlyn": {
4747
"type": "Direct",
@@ -56,8 +56,8 @@
5656
},
5757
"Microsoft.CodeAnalysis.Analyzers": {
5858
"type": "Transitive",
59-
"resolved": "5.3.0-2.final",
60-
"contentHash": "VzdevMuvWpgH5s7bj+Y8CHaAPvJvzdRjBL/f2bzCEugZIOFOCZfblsbHwbCJ3hUFvvrbbcLcTrLt6HIj3bngAw=="
59+
"resolved": "5.3.0-2.25625.1",
60+
"contentHash": "4Yhh2fnu3G+J0J1lDc8WZVgMjgbynSeTfkl5IFJMFrmiIO0sc7Tjx+f3sFVV8Sd35PrIUWfof0RWc3lAMl7Azg=="
6161
},
6262
"Microsoft.CodeAnalysis.Common": {
6363
"type": "Transitive",

0 commit comments

Comments
 (0)