Skip to content

Commit 9ac1344

Browse files
authored
Add change log (#2331)
1 parent 30c1f7a commit 9ac1344

File tree

8 files changed

+42
-34
lines changed

8 files changed

+42
-34
lines changed

logs/log1755877694.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Change Log
2+
3+
- **src/Proto.TestKit/ITestProbe.cs**: Removed public `Context` property and added `Watch`/`Unwatch` methods to limit external access to actor context.
4+
- **src/Proto.TestKit/TestProbe.cs**: Made `Context` property private and added `Watch`/`Unwatch` wrappers so probes no longer expose internal context.
5+
- **src/Proto.TestKit/PropsTestProbeExtensions.cs**: Updated middleware to use new `Send` API instead of accessing probe context directly.
6+
- **src/Proto.TestKit/ProbeMailboxStatistics.cs**: Forward mailbox messages through probe `Send` method, avoiding direct context exposure.
7+
- **tests/Proto.Remote.Tests/RemoteTests.cs**: Replaced `probe.Context.Watch/Unwatch` with new probe methods.
8+
- **tests/Proto.TestKit.Tests/TestProbeAsyncTests.cs**: Removed direct context check, relying on probe methods for mailbox validation.
9+
- **tests/Proto.Actor.Tests/Router/BroadcastPoolRouterTests.cs**: Used implicit PID conversion instead of context access when matching routees.

src/Proto.TestKit/ITestProbe.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ public interface ITestProbe
2222
/// </summary>
2323
PID? Sender { get; }
2424

25-
/// <summary>
26-
/// the context of the test probe
27-
/// </summary>
28-
IContext? Context { get; }
29-
3025
/// <summary>
3126
/// asynchronously checks that no message arrives within the time allowed
3227
/// </summary>
@@ -183,6 +178,18 @@ Task<T> FishForMessageAsync<T>(Func<T, bool> when, TimeSpan? timeAllowed = null,
183178
/// <param name="message"></param>
184179
void Respond(object message);
185180

181+
/// <summary>
182+
/// starts watching the target actor
183+
/// </summary>
184+
/// <param name="pid"></param>
185+
void Watch(PID pid);
186+
187+
/// <summary>
188+
/// stops watching the target actor
189+
/// </summary>
190+
/// <param name="pid"></param>
191+
void Unwatch(PID pid);
192+
186193
/// <summary>
187194
/// sends a request message from the test probe to the target
188195
/// </summary>

src/Proto.TestKit/ProbeMailboxStatistics.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void MessagePosted(object message)
2020
}
2121

2222
public void MessageReceived(object message) =>
23-
_probe.Context.Send(_probe.Context.Self, message);
23+
_probe.Send(_probe, message);
2424

2525
public void MailboxEmpty()
2626
{

src/Proto.TestKit/PropsTestProbeExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static Props WithReceiveProbe(this Props props, TestProbe probe) =>
1515
props.WithReceiverMiddleware(next => async (ctx, env) =>
1616
{
1717
await next(ctx, env);
18-
probe.Context.Send(probe.Context.Self, new MessageEnvelope(env.Message, env.Sender));
18+
probe.Send(probe, new MessageEnvelope(env.Message, env.Sender));
1919
});
2020

2121
/// <summary>
@@ -24,7 +24,7 @@ public static Props WithReceiveProbe(this Props props, TestProbe probe) =>
2424
public static Props WithSendProbe(this Props props, TestProbe probe) =>
2525
props.WithSenderMiddleware(next => async (ctx, target, env) =>
2626
{
27-
probe.Context.Send(probe.Context.Self, new MessageEnvelope(env.Message, target));
27+
probe.Send(probe, new MessageEnvelope(env.Message, target));
2828
await next(ctx, target, env);
2929
});
3030

src/Proto.TestKit/TestProbe.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ public Task ReceiveAsync(IContext context)
4646
/// <inheritdoc />
4747
public PID? Sender { get; private set; }
4848

49-
/// <inheritdoc />
50-
public IContext Context
49+
private IContext Context
5150
{
5251
get
5352
{
@@ -59,7 +58,7 @@ public IContext Context
5958

6059
return _context!;
6160
}
62-
private set => _context = value;
61+
set => _context = value;
6362
}
6463

6564
/// <inheritdoc />
@@ -183,6 +182,10 @@ public Task<T> RequestAsync<T>(PID target, object message, CancellationToken can
183182
public Task<T> RequestAsync<T>(PID target, object message, TimeSpan timeAllowed) =>
184183
Context.RequestAsync<T>(target, message, timeAllowed);
185184

185+
public void Watch(PID pid) => Context.Watch(pid);
186+
187+
public void Unwatch(PID pid) => Context.Unwatch(pid);
188+
186189
public static implicit operator PID?(TestProbe tp) => tp.Context.Self;
187190

188191
private async Task<MessageAndSender> ReceiveNextAsync(TimeSpan? timeAllowed,

tests/Proto.Actor.Tests/Router/BroadcastPoolRouterTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public async Task BroadcastPoolRouter_RemovedRouteesDoNotReceiveMessages()
3535
var routee2 = routees.Pids[1];
3636
var routee3 = routees.Pids[2];
3737

38-
var probe1 = probes.Find(p => p.Context.Self == routee1)!;
39-
var probe2 = probes.Find(p => p.Context.Self == routee2)!;
40-
var probe3 = probes.Find(p => p.Context.Self == routee3)!;
38+
var probe1 = probes.Find(p => (PID)p == routee1)!;
39+
var probe2 = probes.Find(p => (PID)p == routee2)!;
40+
var probe3 = probes.Find(p => (PID)p == routee3)!;
4141

4242
system.Root.Send(router, "first");
4343
await probe1.ExpectNextUserMessageAsync<string>(x => x == "first");

tests/Proto.Remote.Tests/RemoteTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public async Task CanWatchRemoteActor()
165165
var remoteActor = await SpawnRemoteActor(_fixture.RemoteAddress);
166166

167167
var (probe, _) = System.CreateTestProbe();
168-
probe.Context.Watch(remoteActor);
168+
probe.Watch(remoteActor);
169169

170170
await System.Root.PoisonAsync(remoteActor);
171171

@@ -180,8 +180,8 @@ public async Task CanWatchMultipleRemoteActors()
180180
var remoteActor2 = await SpawnRemoteActor(_fixture.RemoteAddress);
181181

182182
var (probe, _) = System.CreateTestProbe();
183-
probe.Context.Watch(remoteActor1);
184-
probe.Context.Watch(remoteActor2);
183+
probe.Watch(remoteActor1);
184+
probe.Watch(remoteActor2);
185185

186186
await System.Root.PoisonAsync(remoteActor1);
187187
await System.Root.PoisonAsync(remoteActor2);
@@ -201,8 +201,8 @@ public async Task MultipleLocalActorsCanWatchRemoteActor()
201201

202202
var (probe1, _) = System.CreateTestProbe();
203203
var (probe2, _) = System.CreateTestProbe();
204-
probe1.Context.Watch(remoteActor);
205-
probe2.Context.Watch(remoteActor);
204+
probe1.Watch(remoteActor);
205+
probe2.Watch(remoteActor);
206206

207207
await System.Root.PoisonAsync(remoteActor);
208208

@@ -218,10 +218,10 @@ public async Task CanUnwatchRemoteActor()
218218

219219
var (probe1, _) = System.CreateTestProbe();
220220
var (probe2, _) = System.CreateTestProbe();
221-
probe1.Context.Watch(remoteActor);
222-
probe2.Context.Watch(remoteActor);
221+
probe1.Watch(remoteActor);
222+
probe2.Watch(remoteActor);
223223

224-
probe2.Context.Unwatch(remoteActor);
224+
probe2.Unwatch(remoteActor);
225225
await Task.Delay(TimeSpan.FromSeconds(3));
226226

227227
await System.Root.PoisonAsync(remoteActor);
@@ -238,7 +238,7 @@ public async Task WhenRemoteTerminated_LocalWatcherReceivesNotification()
238238
var remoteActor = await SpawnRemoteActor(_fixture.RemoteAddress);
239239

240240
var (probe, _) = System.CreateTestProbe();
241-
probe.Context.Watch(remoteActor);
241+
probe.Watch(remoteActor);
242242

243243
System.Root.Send(remoteActor, new Die());
244244

tests/Proto.TestKit.Tests/TestProbeAsyncTests.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,6 @@ public async Task ExpectEmptyMailboxAsync_throws_when_message_present()
5252
var (probe, pid) = system.CreateTestProbe();
5353

5454
system.Root.Send(pid, "hello");
55-
SpinWait.SpinUntil(() =>
56-
{
57-
try
58-
{
59-
return probe.Context != null;
60-
}
61-
catch
62-
{
63-
return false;
64-
}
65-
}, TimeSpan.FromSeconds(1));
6655
await Assert.ThrowsAsync<TestKitException>(() => probe.ExpectEmptyMailboxAsync());
6756
}
6857
}

0 commit comments

Comments
 (0)