Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Proto.Actor/InternalsVisibleTo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@

[assembly: InternalsVisibleTo("Proto.Cluster")]
[assembly: InternalsVisibleTo("Proto.Remote")]
[assembly: InternalsVisibleTo("Proto.OpenTelemetry.Tests")]
[assembly: InternalsVisibleTo("Proto.OpenTelemetry.Tests")]
[assembly: InternalsVisibleTo("Proto.Actor.Tests")]
29 changes: 29 additions & 0 deletions tests/Proto.Actor.Tests/ActorMetricsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using Proto.Metrics;
using Xunit;

namespace Proto.Tests;

public class ActorMetricsTests
{
[Fact]
public void CounterProducesMeasurement()
{
var measurements = new List<long>();
using var listener = new MeterListener();
listener.InstrumentPublished = (instrument, l) =>
{
if (instrument.Name == ActorMetrics.ActorSpawnCount.Name)
{
l.EnableMeasurementEvents(instrument);
}
};
listener.SetMeasurementEventCallback<long>((instrument, value, tags, state) => measurements.Add(value));
listener.Start();

ActorMetrics.ActorSpawnCount.Add(5);

Assert.Contains(5, measurements);
}
}
43 changes: 43 additions & 0 deletions tests/Proto.Actor.Tests/DeduplicationContextTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Threading.Tasks;
using Proto.Deduplication;
using Proto;
using Xunit;

namespace Proto.Tests;

public class DeduplicationContextTests
{
[Fact]
public async Task DuplicatesAreIgnored()
{
await using var system = new ActorSystem();
var context = system.Root;
var count = 0;

var props = Props.FromFunc(ctx =>
{
if (ctx.Message is string)
{
count++;
}
return Task.CompletedTask;
}).WithContextDecorator(c => new DeduplicationContext<string>(
c,
TimeSpan.FromSeconds(5),
(MessageEnvelope env, out string? key) =>
{
key = env.Message as string;
return key != null;
}
));

var pid = context.Spawn(props);
context.Send(pid, "one");
context.Send(pid, "one");
context.Send(pid, "two");
await Task.Delay(100);

Assert.Equal(2, count);
}
}
30 changes: 30 additions & 0 deletions tests/Proto.Actor.Tests/FunctionActorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Threading.Tasks;
using Xunit;

namespace Proto.Tests;

public class FunctionActorTests
{
[Fact]
public async Task FunctionActorHandlesMessages()
{
await using var system = new ActorSystem();
var context = system.Root;
var received = false;

var props = Props.FromFunc(ctx =>
{
if (ctx.Message is string)
{
received = true;
}
return Task.CompletedTask;
});

var pid = context.Spawn(props);
context.Send(pid, "hello");
await Task.Delay(50);

Assert.True(received);
}
}
31 changes: 31 additions & 0 deletions tests/Proto.Actor.Tests/ObservableGaugeWrapperTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using System.Linq;
using Proto.Metrics;
using Xunit;

namespace Proto.Tests;

public class ObservableGaugeWrapperTests
{
[Fact]
public void ObserverManagementWorks()
{
var gauge = new ObservableGaugeWrapper<int>();
Func<IEnumerable<Measurement<int>>> obs1 = () => new[] { new Measurement<int>(1) };
Func<IEnumerable<Measurement<int>>> obs2 = () => new[] { new Measurement<int>(2) };

gauge.AddObserver(obs1);
gauge.AddObserver(obs2);

var values = gauge.Observe().Select(m => m.Value).ToArray();
Assert.Contains(1, values);
Assert.Contains(2, values);

gauge.RemoveObserver(obs1);
values = gauge.Observe().Select(m => m.Value).ToArray();
Assert.DoesNotContain(1, values);
Assert.Contains(2, values);
}
}
Loading