Skip to content

Commit

Permalink
fix: Patch work for internet status chekcing execution to make it com…
Browse files Browse the repository at this point in the history
…patible with single threaded environment.

Disable ee for unit/integration tests
  • Loading branch information
mohitpubnub committed Oct 28, 2024
1 parent 36185e4 commit 08f37c3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/Api/PubnubApi/ClientNetworkStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ internal static class ClientNetworkStatus

public static IPubnubLog PubnubLog { get; set; }

internal static async Task<bool> CheckInternetStatus<T>(bool systemActive, PNOperationType type, PNCallback<T> callback, string[] channels, string[] channelGroups)
internal static bool CheckInternetStatus<T>(bool systemActive, PNOperationType type, PNCallback<T> callback, string[] channels, string[] channelGroups)
{
if (unit != null) {
return unit.InternetAvailable;
} else {
try {
await CheckClientNetworkAvailability(CallbackClientNetworkStatus, type, callback, channels, channelGroups).ConfigureAwait(false);
return CheckClientNetworkAvailability(CallbackClientNetworkStatus, type, callback, channels, channelGroups);
} catch (AggregateException ae) {
foreach (var ie in ae.InnerExceptions) {
LoggingMethod.WriteToLog(pubnubLog, string.Format(CultureInfo.InvariantCulture, "DateTime {0} AggregateException CheckInternetStatus Error: {1} {2} ", DateTime.Now.ToString(CultureInfo.InvariantCulture), ie.GetType().Name, ie.Message), pubnubConfig.LogVerbosity);
Expand All @@ -57,7 +57,7 @@ internal static bool IsInternetCheckRunning()
return isInternetCheckRunning;
}

private static async Task<bool> CheckClientNetworkAvailability<T>(Action<bool> internalCallback, PNOperationType type, PNCallback<T> callback, string[] channels, string[] channelGroups)
private static bool CheckClientNetworkAvailability<T>(Action<bool> internalCallback, PNOperationType type, PNCallback<T> callback, string[] channels, string[] channelGroups)
{
lock (internetCheckLock) {
if (isInternetCheckRunning) {
Expand All @@ -75,7 +75,7 @@ private static async Task<bool> CheckClientNetworkAvailability<T>(Action<bool> i
ChannelGroups = channelGroups
};

networkStatus = await CheckSocketConnect<T>(state).ConfigureAwait(false);
CheckSocketConnect<T>(state).ConfigureAwait(false);
return networkStatus;
}

Expand All @@ -100,6 +100,7 @@ private static async Task<bool> CheckSocketConnect<T>(object internetState)
try {
var gotTimeResp = await GetTimeWithTaskFactoryAsync().ConfigureAwait(false);
isInternetCheckRunning = gotTimeResp;
networkStatus = gotTimeResp;
} catch (Exception ex) {
networkStatus = false;
LoggingMethod.WriteToLog(pubnubLog, string.Format(CultureInfo.InvariantCulture, "DateTime {0} CheckSocketConnect (HttpClient Or Task.Factory) Failed {1}", DateTime.Now.ToString(CultureInfo.InvariantCulture), ex.Message), pubnubConfig.LogVerbosity);
Expand Down
2 changes: 1 addition & 1 deletion src/Api/PubnubApi/PubnubCoreBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ protected bool CheckInternetConnectionStatus<T>(bool systemActive, PNOperationTy
if (!ClientNetworkStatus.IsInternetCheckRunning())
{
clientNetworkStatusInternetStatus = ClientNetworkStatus
.CheckInternetStatus<T>(PubnetSystemActive, type, callback, channels, channelGroups).Result;
.CheckInternetStatus<T>(PubnetSystemActive, type, callback, channels, channelGroups);
}
return clientNetworkStatusInternetStatus;
}
Expand Down
1 change: 1 addition & 0 deletions src/UnitTests/PubnubApi.Tests/TestHarness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ protected static Pubnub createPubNubInstance(PNConfiguration pnConfiguration, st
else
{
pnConfiguration.Origin = "ps.pndsn.com";
pnConfiguration.EnableEventEngine = false;
pubnub = new Pubnub(pnConfiguration);
}
if (!string.IsNullOrEmpty(authToken))
Expand Down

0 comments on commit 08f37c3

Please sign in to comment.