Skip to content

Commit

Permalink
Merge pull request #1234 from SteeltoeOSS/fix-broken-cibuild
Browse files Browse the repository at this point in the history
Fix broken cibuild
  • Loading branch information
bart-vmware authored Dec 20, 2023
2 parents 2018cf7 + 8a64f89 commit a4ede3a
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 77 deletions.
2 changes: 1 addition & 1 deletion build/templates/component-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: 1
SolutionFile: src/Steeltoe.${{parameters.component}}.slnf
CommonTestArgs: --blame-hang-timeout 3m --no-build -c Release --collect "XPlat Code Coverage" -maxcpucount:1 --settings coverlet.runsettings --logger trx --results-directory $(Build.SourcesDirectory)
CommonTestArgs: --blame-crash --blame-hang-timeout 3m --no-build -c Release --collect "XPlat Code Coverage" -maxcpucount:1 --settings coverlet.runsettings --logger trx --results-directory $(Build.SourcesDirectory)
pool:
vmImage: ${{parameters.OS}}-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion shared-test.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
<PackageReference Include="Moq" Version="$(MoqVersion)" />
<PackageReference Include="xunit" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVisualStudioVersion)" />
</ItemGroup>

<ItemGroup Condition="Exists('xunit.runner.json')">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage reques
{
var responseMessage = new HttpResponseMessage(HttpStatusCode.OK);
responseMessage.Headers.Add("requestUri", request.RequestUri.AbsoluteUri);
return Task.Factory.StartNew(() => responseMessage, cancellationToken);
return Task.FromResult(responseMessage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage reques
{
var responseMessage = new HttpResponseMessage(HttpStatusCode.InternalServerError);
responseMessage.Headers.Add("requestUri", request.RequestUri.AbsoluteUri);
return Task.Factory.StartNew(() => responseMessage, cancellationToken);
return Task.FromResult(responseMessage);
}
}
41 changes: 26 additions & 15 deletions src/Configuration/src/Encryption/EncryptionResolverProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ internal sealed class EncryptionResolverProvider : IConfigurationProvider, IDisp
{
// regex for matching {cipher}{key:keyAlias} at the start of the string
private readonly Regex _cipherRegex = new("^{cipher}({key:(?<alias>.*)})?(?<cipher>.*)");
private bool _isDisposed;
internal ILogger<EncryptionResolverProvider> Logger { get; }

/// <summary>
Expand Down Expand Up @@ -188,35 +189,45 @@ public IEnumerable<string> GetChildKeys(IEnumerable<string> earlierKeys, string

private void EnsureInitialized()
{
if (_isDisposed)
{
throw new ObjectDisposedException(nameof(EncryptionResolverProvider));
}

Configuration ??= new ConfigurationRoot(Providers);
}

public void Dispose()
{
HashSet<IDisposable> disposables = new();

foreach (IConfigurationProvider provider in Providers)
if (!_isDisposed)
{
if (provider is IDisposable disposable)
{
disposables.Add(disposable);
}
}
HashSet<IDisposable> disposables = new();

if (Configuration != null)
{
foreach (IConfigurationProvider provider in Configuration.Providers)
foreach (IConfigurationProvider provider in Providers)
{
if (provider is IDisposable disposable)
{
disposables.Add(disposable);
}
}
}

foreach (IDisposable disposable in disposables)
{
disposable.Dispose();
if (Configuration != null)
{
foreach (IConfigurationProvider provider in Configuration.Providers)
{
if (provider is IDisposable disposable)
{
disposables.Add(disposable);
}
}
}

foreach (IDisposable disposable in disposables)
{
disposable.Dispose();
}

_isDisposed = true;
}
}
}
10 changes: 9 additions & 1 deletion src/Configuration/src/Kubernetes/KubernetesProviderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@ protected void StartPolling(int interval)
{
Thread.Sleep(TimeSpan.FromSeconds(interval));
Logger.LogTrace("Interval completed for {namespace}.{name}, beginning reload", Settings.Namespace, Settings.Name);
Load();
try
{
Load();
}
catch (Exception exception) when (!exception.IsCancellation())
{
Logger.LogError("Failed to load configuration.");
}
if (_cancellationToken.IsCancellationRequested)
{
Expand Down
41 changes: 26 additions & 15 deletions src/Configuration/src/Placeholder/PlaceholderResolverProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Steeltoe.Configuration.Placeholder;
/// </summary>
internal sealed class PlaceholderResolverProvider : IPlaceholderResolverProvider, IDisposable
{
private bool _isDisposed;
internal ILogger<PlaceholderResolverProvider> Logger { get; }

public IList<IConfigurationProvider> Providers { get; } = new List<IConfigurationProvider>();
Expand Down Expand Up @@ -161,35 +162,45 @@ public IEnumerable<string> GetChildKeys(IEnumerable<string> earlierKeys, string

private void EnsureInitialized()
{
if (_isDisposed)
{
throw new ObjectDisposedException(nameof(PlaceholderResolverProvider));
}

Configuration ??= new ConfigurationRoot(Providers);
}

public void Dispose()
{
HashSet<IDisposable> disposables = new();

foreach (IConfigurationProvider provider in Providers)
if (!_isDisposed)
{
if (provider is IDisposable disposable)
{
disposables.Add(disposable);
}
}
HashSet<IDisposable> disposables = new();

if (Configuration != null)
{
foreach (IConfigurationProvider provider in Configuration.Providers)
foreach (IConfigurationProvider provider in Providers)
{
if (provider is IDisposable disposable)
{
disposables.Add(disposable);
}
}
}

foreach (IDisposable disposable in disposables)
{
disposable.Dispose();
if (Configuration != null)
{
foreach (IConfigurationProvider provider in Configuration.Providers)
{
if (provider is IDisposable disposable)
{
disposables.Add(disposable);
}
}
}

foreach (IDisposable disposable in disposables)
{
disposable.Dispose();
}

_isDisposed = true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1403,14 +1403,10 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage

private sealed class TestServiceInfo : IServiceInstance
{
public string ServiceId => throw new NotImplementedException();

public string Host => throw new NotImplementedException();

public int Port => throw new NotImplementedException();

public bool IsSecure => throw new NotImplementedException();

public string ServiceId { get; }
public string Host { get; }
public int Port { get; }
public bool IsSecure { get; }
public Uri Uri { get; }

public IDictionary<string, string> Metadata { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ internal sealed class TestDiscoveryClient : IDiscoveryClient
{
internal bool HasShutdown { get; private set; }

public string Description => throw new NotImplementedException();
public string Description => string.Empty;

public Task<IList<string>> GetServicesAsync(CancellationToken cancellationToken)
{
throw new NotImplementedException();
return Task.FromResult<IList<string>>(Array.Empty<string>());
}

public Task<IList<IServiceInstance>> GetInstancesAsync(string serviceId, CancellationToken cancellationToken)
{
throw new NotImplementedException();
return Task.FromResult<IList<IServiceInstance>>(Array.Empty<IServiceInstance>());
}

public Task<IServiceInstance> GetLocalServiceInstanceAsync(CancellationToken cancellationToken)
{
throw new NotImplementedException();
return Task.FromResult<IServiceInstance>(new JsonSerializableServiceInstance());
}

public Task ShutdownAsync(CancellationToken cancellationToken)
Expand Down
72 changes: 45 additions & 27 deletions src/Discovery/src/Eureka/DiscoveryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Steeltoe.Discovery.Eureka;
public class DiscoveryClient : IEurekaClient
{
protected readonly ApplicationInfoManager AppInfoManager;
private int _shutdown;
protected Timer heartBeatTimer;
protected Timer cacheRefreshTimer;
protected volatile Applications localRegionApps;
Expand All @@ -25,7 +26,6 @@ public class DiscoveryClient : IEurekaClient
protected ILogger logger;
protected ILogger regularLogger;
protected ILogger startupLogger;
protected int shutdown;

internal Timer HeartBeatTimer => heartBeatTimer;

Expand Down Expand Up @@ -202,7 +202,7 @@ public InstanceInfo GetNextServerFromEureka(string virtualHostname, bool secure)

public virtual async Task ShutdownAsync(CancellationToken cancellationToken)
{
int shutdownValue = Interlocked.Exchange(ref shutdown, 1);
int shutdownValue = Interlocked.Exchange(ref _shutdown, 1);

if (shutdownValue > 0)
{
Expand Down Expand Up @@ -248,33 +248,33 @@ public InstanceStatus GetInstanceRemoteStatus()
return InstanceStatus.Unknown;
}

internal async void HandleInstanceStatusChanged(object sender, StatusChangedEventArgs args)
private async void HandleInstanceStatusChanged(object sender, StatusChangedEventArgs args)
{
InstanceInfo info = AppInfoManager.InstanceInfo;

if (info != null)
try
{
logger.LogDebug("HandleInstanceStatusChanged {previousStatus}, {currentStatus}, {instanceId}, {dirty}", args.Previous, args.Current,
args.InstanceId, info.IsDirty);
InstanceInfo info = AppInfoManager.InstanceInfo;

if (info.IsDirty)
if (info != null)
{
try
logger.LogDebug("HandleInstanceStatusChanged {previousStatus}, {currentStatus}, {instanceId}, {dirty}", args.Previous, args.Current,
args.InstanceId, info.IsDirty);

if (info.IsDirty)
{
bool result = await RegisterAsync(CancellationToken.None);

if (result)
{
info.IsDirty = false;
logger.LogInformation("HandleInstanceStatusChanged RegisterAsync Succeed");
logger.LogInformation("HandleInstanceStatusChanged RegisterAsync succeeded");
}
}
catch (Exception e)
{
logger.LogError(e, "HandleInstanceStatusChanged RegisterAsync Failed");
}
}
}
catch (Exception exception)
{
logger.LogError(exception, "HandleInstanceStatusChanged failed");
}
}

protected internal Timer StartTimer(string name, int interval, Action task)
Expand Down Expand Up @@ -631,31 +631,49 @@ private void UpdateInstanceRemoteStatus()
// both of these should fire and forget on execution but log failures
private async void HeartBeatTask()
{
if (shutdown > 0)
try
{
return;
}
int shutdownValue = Interlocked.Add(ref _shutdown, 0);

if (shutdownValue > 0)
{
return;
}

bool result = await RenewAsync(CancellationToken.None);
bool result = await RenewAsync(CancellationToken.None);

if (!result)
if (!result)
{
logger.LogError("HeartBeat failed");
}
}
catch (Exception exception)
{
logger.LogError("HeartBeat failed");
logger.LogError(exception, "HeartBeat failed");
}
}

private async void CacheRefreshTask()
{
if (shutdown > 0)
try
{
return;
}
int shutdownValue = Interlocked.Add(ref _shutdown, 0);

if (shutdownValue > 0)
{
return;
}

bool result = await FetchRegistryAsync(false, CancellationToken.None);
bool result = await FetchRegistryAsync(false, CancellationToken.None);

if (!result)
if (!result)
{
logger.LogError("CacheRefresh failed");
}
}
catch (Exception exception)
{
logger.LogError("CacheRefresh failed");
logger.LogError(exception, "CacheRefresh failed");
}
}
}
3 changes: 3 additions & 0 deletions src/Steeltoe.Configuration.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"Configuration\\src\\CloudFoundry.ServiceBinding\\Steeltoe.Configuration.CloudFoundry.ServiceBinding.csproj",
"Configuration\\src\\CloudFoundry\\Steeltoe.Configuration.CloudFoundry.csproj",
"Configuration\\src\\ConfigServer\\Steeltoe.Configuration.ConfigServer.csproj",
"Configuration\\src\\Encryption\\Steeltoe.Configuration.Encryption.csproj",
"Configuration\\src\\Kubernetes.ServiceBinding\\Steeltoe.Configuration.Kubernetes.ServiceBinding.csproj",
"Configuration\\src\\Kubernetes\\Steeltoe.Configuration.Kubernetes.csproj",
"Configuration\\src\\Placeholder\\Steeltoe.Configuration.Placeholder.csproj",
Expand All @@ -22,12 +23,14 @@
"Configuration\\test\\CloudFoundry.Test\\Steeltoe.Configuration.CloudFoundry.Test.csproj",
"Configuration\\test\\ConfigServer.Integration.Test\\Steeltoe.Configuration.ConfigServer.Integration.Test.csproj",
"Configuration\\test\\ConfigServer.Test\\Steeltoe.Configuration.ConfigServer.Test.csproj",
"Configuration\\test\\Encryption.Test\\Steeltoe.Configuration.Encryption.Test.csproj",
"Configuration\\test\\Kubernetes.ServiceBinding.Test\\Steeltoe.Configuration.Kubernetes.ServiceBinding.Test.csproj",
"Configuration\\test\\Kubernetes.Test\\Steeltoe.Configuration.Kubernetes.Test.csproj",
"Configuration\\test\\Placeholder.Test\\Steeltoe.Configuration.Placeholder.Test.csproj",
"Configuration\\test\\RandomValue.Test\\Steeltoe.Configuration.RandomValue.Test.csproj",
"Configuration\\test\\SpringBoot.Test\\Steeltoe.Configuration.SpringBoot.Test.csproj",
"Connectors\\src\\Abstractions\\Steeltoe.Connectors.Abstractions.csproj",
"Connectors\\src\\CloudFoundry\\Steeltoe.Connectors.CloudFoundry.csproj",
"Connectors\\src\\Connectors\\Steeltoe.Connectors.csproj",
"Discovery\\src\\Abstractions\\Steeltoe.Discovery.Abstractions.csproj",
"Discovery\\src\\Client\\Steeltoe.Discovery.Client.csproj",
Expand Down
Loading

0 comments on commit a4ede3a

Please sign in to comment.