Skip to content

Commit 7193337

Browse files
authored
Support adding additional error handling to generated actors (#2141)
* Support adding additional error handling to generated actors updates for tests * add delay for flaky test
1 parent 87f19b1 commit 7193337

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

src/Proto.Cluster.CodeGen/Template.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,19 @@ public abstract class {{Name}}Base
6262
}
6363
catch (Exception x)
6464
{
65-
onError(x.ToString());
65+
OnError(x);
6666
}
6767
}
6868
{{/each}}
6969
7070
{{#each Methods}}
7171
public abstract Task{{#if UseReturn}}<{{OutputName}}>{{/if}} {{Name}}({{SingleParameterDefinition}});
7272
{{/each}}
73+
74+
public virtual void OnError(Exception ex)
75+
{
76+
Context!.Respond(new global::Proto.Cluster.GrainErrorResponse { Err = ex.ToString() });
77+
}
7378
}
7479
7580
public class {{Name}}Client

tests/Proto.Cluster.CodeGen.Tests/ExpectedOutput.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public virtual async Task GetState(Action<Acme.Mysystem.Bar.GetCurrentStateRespo
4242
}
4343
catch (Exception x)
4444
{
45-
onError(x.ToString());
45+
OnError(x);
4646
}
4747
}
4848
public virtual async Task SendCommand(Acme.Mysystem.Bar.SomeCommand request, Action respond, Action<string> onError)
@@ -54,7 +54,7 @@ public virtual async Task SendCommand(Acme.Mysystem.Bar.SomeCommand request, Act
5454
}
5555
catch (Exception x)
5656
{
57-
onError(x.ToString());
57+
OnError(x);
5858
}
5959
}
6060
public virtual async Task RequestResponse(Acme.Mysystem.Bar.Query request, Action<Acme.Mysystem.Bar.Response> respond, Action<string> onError)
@@ -66,7 +66,7 @@ public virtual async Task RequestResponse(Acme.Mysystem.Bar.Query request, Actio
6666
}
6767
catch (Exception x)
6868
{
69-
onError(x.ToString());
69+
OnError(x);
7070
}
7171
}
7272
public virtual async Task NoParameterOrReturn(Action respond, Action<string> onError)
@@ -78,14 +78,19 @@ public virtual async Task NoParameterOrReturn(Action respond, Action<string> onE
7878
}
7979
catch (Exception x)
8080
{
81-
onError(x.ToString());
81+
OnError(x);
8282
}
8383
}
8484

8585
public abstract Task<Acme.Mysystem.Bar.GetCurrentStateResponse> GetState();
8686
public abstract Task SendCommand(Acme.Mysystem.Bar.SomeCommand request);
8787
public abstract Task<Acme.Mysystem.Bar.Response> RequestResponse(Acme.Mysystem.Bar.Query request);
8888
public abstract Task NoParameterOrReturn();
89+
90+
public virtual void OnError(Exception ex)
91+
{
92+
Context!.Respond(new global::Proto.Cluster.GrainErrorResponse { Err = ex.ToString() });
93+
}
8994
}
9095

9196
public class TestGrainClient

tests/Proto.Cluster.CodeGen.Tests/ExpectedOutputPackageless.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public virtual async Task GetState(Action<Acme.Mysystem.Bar.GetCurrentStateRespo
4242
}
4343
catch (Exception x)
4444
{
45-
onError(x.ToString());
45+
OnError(x);
4646
}
4747
}
4848
public virtual async Task SendCommand(Acme.Mysystem.Bar.SomeCommand request, Action respond, Action<string> onError)
@@ -54,7 +54,7 @@ public virtual async Task SendCommand(Acme.Mysystem.Bar.SomeCommand request, Act
5454
}
5555
catch (Exception x)
5656
{
57-
onError(x.ToString());
57+
OnError(x);
5858
}
5959
}
6060
public virtual async Task RequestResponse(Acme.Mysystem.Bar.Query request, Action<Acme.Mysystem.Bar.Response> respond, Action<string> onError)
@@ -66,7 +66,7 @@ public virtual async Task RequestResponse(Acme.Mysystem.Bar.Query request, Actio
6666
}
6767
catch (Exception x)
6868
{
69-
onError(x.ToString());
69+
OnError(x);
7070
}
7171
}
7272
public virtual async Task NoParameterOrReturn(Action respond, Action<string> onError)
@@ -78,14 +78,19 @@ public virtual async Task NoParameterOrReturn(Action respond, Action<string> onE
7878
}
7979
catch (Exception x)
8080
{
81-
onError(x.ToString());
81+
OnError(x);
8282
}
8383
}
8484

8585
public abstract Task<Acme.Mysystem.Bar.GetCurrentStateResponse> GetState();
8686
public abstract Task SendCommand(Acme.Mysystem.Bar.SomeCommand request);
8787
public abstract Task<Acme.Mysystem.Bar.Response> RequestResponse(Acme.Mysystem.Bar.Query request);
8888
public abstract Task NoParameterOrReturn();
89+
90+
public virtual void OnError(Exception ex)
91+
{
92+
Context!.Respond(new global::Proto.Cluster.GrainErrorResponse { Err = ex.ToString() });
93+
}
8994
}
9095

9196
public class TestGrainClient

tests/Proto.Cluster.PartitionIdentity.Tests/PartitionIdentityTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ PartitionIdentityLookup.Send send
8383
timer.Restart();
8484
await fixture.DisposeAsync();
8585
_output.WriteLine($"Stopped cluster in {timer.Elapsed}");
86+
87+
// delay to reduce flakiness
88+
await Task.Delay(2000);
8689

8790
var actorStates = fixture.Repository.Contents.ToList();
8891

0 commit comments

Comments
 (0)