Skip to content

Commit

Permalink
Issue #54 - Event on session refresh is called several times in the page
Browse files Browse the repository at this point in the history
Add new RefreshEnded SessionStateKind to propagate after Session.Refresh
  • Loading branch information
mserra-github committed Nov 13, 2023
1 parent b9c9e45 commit 9d37d5d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ namespace COMET.Web.Common.Tests.Services.SessionManagement

using COMET.Web.Common.Enumerations;
using COMET.Web.Common.Services.SessionManagement;

using Moq;

using NUnit.Framework;
Expand Down Expand Up @@ -305,5 +304,17 @@ public void VerifyDeleteThings()

Assert.DoesNotThrow(() => this.sessionService.DeleteThing(this.iteration, element.Clone(false)));
}

[Test]
public void VerifyRefreshEndedCalled()
{
var onSessionRefreshedCalled = false;
void SetRefreshEndedCalled() { onSessionRefreshedCalled = true; }
CDPMessageBus.Current.Listen<SessionStateKind>().Where(x => x == SessionStateKind.RefreshEnded)
.Subscribe(_ => { SetRefreshEndedCalled(); });
this.sessionService.RefreshSession();

Assert.That(onSessionRefreshedCalled, Is.True);
}
}
}
7 changes: 6 additions & 1 deletion COMET.Web.Common/Enumerations/SessionStateKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public enum SessionStateKind
/// <summary>
/// When refresh is in progress
/// </summary>
Refreshing
Refreshing,

/// <summary>
/// When refresh is finished
/// </summary>
RefreshEnded
}
}
2 changes: 2 additions & 0 deletions COMET.Web.Common/Services/SessionManagement/SessionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ public async Task RefreshSession()

await this.Session.Refresh();

CDPMessageBus.Current.SendMessage(SessionStateKind.RefreshEnded);

Console.WriteLine($"Session refreshed in {sw.ElapsedMilliseconds} [ms]");
}

Expand Down

0 comments on commit 9d37d5d

Please sign in to comment.