Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ private void EmitProviderEvent(ProviderEventTypes type, string message)
payload.Message = message;
}

if (type == ProviderEventTypes.ProviderError)
{
payload.ErrorType = ErrorType.General;
}

// Trigger the task do run, but don't wait for it. We wrap the exceptions inside SafeWrite,
// so we aren't going to have unexpected exceptions here.
Task.Run(() => SafeWrite(payload)).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using LaunchDarkly.Sdk.Server;
using LaunchDarkly.Sdk.Server.Interfaces;
using Moq;
using OpenFeature.Constant;
using OpenFeature.Model;
using Xunit;
using LaunchDarkly.Sdk.Server.Integrations;
Expand Down Expand Up @@ -273,6 +274,36 @@ public async Task ItEmitsConfigurationChangedEvents()
Assert.NotEqual(eventPayloadA?.FlagsChanged[0], eventPayloadB?.FlagsChanged[0]);
}

[Fact(Timeout = 5000)]
public async Task ItIncludesAnErrorTypeInErrorEvents()
{
var mockClient = new Mock<ILdClient>();
mockClient.Setup(l => l.GetLogger())
.Returns(Components.NoLogging.Build(null).LogAdapter.Logger(null));
mockClient.Setup(l => l.Initialized).Returns(true);

var mockDataSourceStatus = new Mock<IDataSourceStatusProvider>();
mockDataSourceStatus.Setup(l => l.Status).Returns(new DataSourceStatus
{
State = DataSourceState.Valid
});
mockClient.Setup(l => l.DataSourceStatusProvider).Returns(mockDataSourceStatus.Object);

var mockFlagTracker = new Mock<IFlagTracker>();
mockClient.Setup(l => l.FlagTracker).Returns(mockFlagTracker.Object);

var provider = new Provider(mockClient.Object);
await provider.InitializeAsync(EvaluationContext.Empty);

mockDataSourceStatus.Raise(e => e.StatusChanged += null,
mockDataSourceStatus.Object,
new DataSourceStatus { State = DataSourceState.Off });

var errorEvent = await provider.GetEventChannel().Reader.ReadAsync() as ProviderEventPayload;
Assert.Equal(ProviderEventTypes.ProviderError, errorEvent?.Type);
Assert.Equal(ErrorType.General, errorEvent?.ErrorType);
}

[Fact(Timeout = 5000)]
public void ItTracksCustomEvents()
{
Expand Down
Loading