Skip to content

Commit 8c2160c

Browse files
authored
chore: remove unneeded tests (#2204)
1 parent 1098723 commit 8c2160c

File tree

5 files changed

+135
-1
lines changed

5 files changed

+135
-1
lines changed

src/Proto.Actor/InternalsVisibleTo.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88

99
[assembly: InternalsVisibleTo("Proto.Cluster")]
1010
[assembly: InternalsVisibleTo("Proto.Remote")]
11-
[assembly: InternalsVisibleTo("Proto.OpenTelemetry.Tests")]
11+
[assembly: InternalsVisibleTo("Proto.OpenTelemetry.Tests")]
12+
[assembly: InternalsVisibleTo("Proto.Actor.Tests")]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Collections.Generic;
2+
using System.Diagnostics.Metrics;
3+
using Proto.Metrics;
4+
using Xunit;
5+
6+
namespace Proto.Tests;
7+
8+
public class ActorMetricsTests
9+
{
10+
[Fact]
11+
public void CounterProducesMeasurement()
12+
{
13+
var measurements = new List<long>();
14+
using var listener = new MeterListener();
15+
listener.InstrumentPublished = (instrument, l) =>
16+
{
17+
if (instrument.Name == ActorMetrics.ActorSpawnCount.Name)
18+
{
19+
l.EnableMeasurementEvents(instrument);
20+
}
21+
};
22+
listener.SetMeasurementEventCallback<long>((instrument, value, tags, state) => measurements.Add(value));
23+
listener.Start();
24+
25+
ActorMetrics.ActorSpawnCount.Add(5);
26+
27+
Assert.Contains(5, measurements);
28+
}
29+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Proto.Deduplication;
4+
using Proto;
5+
using Xunit;
6+
7+
namespace Proto.Tests;
8+
9+
public class DeduplicationContextTests
10+
{
11+
[Fact]
12+
public async Task DuplicatesAreIgnored()
13+
{
14+
await using var system = new ActorSystem();
15+
var context = system.Root;
16+
var count = 0;
17+
18+
var props = Props.FromFunc(ctx =>
19+
{
20+
if (ctx.Message is string)
21+
{
22+
count++;
23+
}
24+
return Task.CompletedTask;
25+
}).WithContextDecorator(c => new DeduplicationContext<string>(
26+
c,
27+
TimeSpan.FromSeconds(5),
28+
(MessageEnvelope env, out string? key) =>
29+
{
30+
key = env.Message as string;
31+
return key != null;
32+
}
33+
));
34+
35+
var pid = context.Spawn(props);
36+
context.Send(pid, "one");
37+
context.Send(pid, "one");
38+
context.Send(pid, "two");
39+
await Task.Delay(100);
40+
41+
Assert.Equal(2, count);
42+
}
43+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Threading.Tasks;
2+
using Xunit;
3+
4+
namespace Proto.Tests;
5+
6+
public class FunctionActorTests
7+
{
8+
[Fact]
9+
public async Task FunctionActorHandlesMessages()
10+
{
11+
await using var system = new ActorSystem();
12+
var context = system.Root;
13+
var received = false;
14+
15+
var props = Props.FromFunc(ctx =>
16+
{
17+
if (ctx.Message is string)
18+
{
19+
received = true;
20+
}
21+
return Task.CompletedTask;
22+
});
23+
24+
var pid = context.Spawn(props);
25+
context.Send(pid, "hello");
26+
await Task.Delay(50);
27+
28+
Assert.True(received);
29+
}
30+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics.Metrics;
4+
using System.Linq;
5+
using Proto.Metrics;
6+
using Xunit;
7+
8+
namespace Proto.Tests;
9+
10+
public class ObservableGaugeWrapperTests
11+
{
12+
[Fact]
13+
public void ObserverManagementWorks()
14+
{
15+
var gauge = new ObservableGaugeWrapper<int>();
16+
Func<IEnumerable<Measurement<int>>> obs1 = () => new[] { new Measurement<int>(1) };
17+
Func<IEnumerable<Measurement<int>>> obs2 = () => new[] { new Measurement<int>(2) };
18+
19+
gauge.AddObserver(obs1);
20+
gauge.AddObserver(obs2);
21+
22+
var values = gauge.Observe().Select(m => m.Value).ToArray();
23+
Assert.Contains(1, values);
24+
Assert.Contains(2, values);
25+
26+
gauge.RemoveObserver(obs1);
27+
values = gauge.Observe().Select(m => m.Value).ToArray();
28+
Assert.DoesNotContain(1, values);
29+
Assert.Contains(2, values);
30+
}
31+
}

0 commit comments

Comments
 (0)