public async Task Roundtrip() { using (var directory = new DisposableDirectory(FileSystem)) { const Capabilities capabilities = Capabilities.Heartbeat; var pins = ContentHashes.Select(x => x.Serialize()).ToList(); var expirationTicks = DateTime.UtcNow.Ticks; var sessionInfo = new HibernatedSessionInfo(1, SessionName, ImplicitPin.None, CacheName, pins, expirationTicks, capabilities); var sessions1 = new HibernatedSessions(new List <HibernatedSessionInfo> { sessionInfo }); await sessions1.WriteAsync(FileSystem, directory.Path); FileSystem.HibernatedSessionsExists(directory.Path).Should().BeTrue(); var fileSize = FileSystem.GetFileSize(directory.Path / HibernatedSessionsExtensions.FileName); fileSize.Should().BeGreaterThan(0); var sessions2 = await FileSystem.ReadHibernatedSessionsAsync(directory.Path); sessions2.Sessions.Count.Should().Be(1); sessions2.Sessions[0].Pins.Count.Should().Be(ContentHashCount); sessions2.Sessions[0].ExpirationUtcTicks.Should().Be(expirationTicks); sessions2.Sessions[0].Capabilities.Should().Be(capabilities); await FileSystem.DeleteHibernatedSessions(directory.Path); } }
public async Task HibernationDataNotLoadedIfStoreStartupFails() { const string scenario = nameof(HibernationDataNotLoadedIfStoreStartupFails); var context = new Context(Logger); using (var directory = new DisposableDirectory(FileSystem)) { var rootPath = directory.Path; var contentHash = ContentHash.Random(); var pins = new List <string> { contentHash.Serialize() }; var hibernatedSessionInfo = new HibernatedSessionInfo(SessionId, SessionName, ImplicitPin.None, CacheName, pins, 0, Capabilities.None); var hibernatedSessions = new HibernatedSessions(new List <HibernatedSessionInfo> { hibernatedSessionInfo }); await hibernatedSessions.WriteAsync(FileSystem, rootPath); var namedCacheRoots = new Dictionary <string, AbsolutePath> { { CacheName, rootPath } }; var grpcPort = PortExtensions.GetNextAvailablePort(); var grpcPortFileName = Guid.NewGuid().ToString(); var configuration = new ServiceConfiguration(namedCacheRoots, rootPath, MaxConnections, GracefulShutdownSeconds, grpcPort, grpcPortFileName); Func <AbsolutePath, IContentStore> contentStoreFactory = (path) => new TestFailingContentStore(); var localContentServerConfiguration = new LocalServerConfiguration(configuration) { UnusedSessionHeartbeatTimeout = TimeSpan.FromSeconds(TimeoutSecs), UnusedSessionTimeout = TimeSpan.FromSeconds(TimeoutSecs * 4), RequestCallTokensPerCompletionQueue = 10, }; using (var server = new LocalContentServer(FileSystem, Logger, scenario, contentStoreFactory, localContentServerConfiguration)) { var r = await server.StartupAsync(context); r.ShouldBeError(TestFailingContentStore.FailureMessage); FileSystem.HibernatedSessionsExists(rootPath).Should().BeTrue("The hibernation data should not have been read/deleted"); } } }
[Trait("Category", "QTestSkip")] // Skipped public async Task RestoredSessionReleasedAfterInactivity() { const string scenario = nameof(RestoredSessionReleasedAfterInactivity); var context = new Context(Logger); using (var directory = new DisposableDirectory(FileSystem)) { var rootPath = directory.Path; var contentHash = ContentHash.Random(); var pins = new List <string> { contentHash.Serialize() }; var hibernatedSessionInfo = new HibernatedSessionInfo(SessionId, SessionName, ImplicitPin.None, CacheName, pins, DateTime.UtcNow.Ticks, Capabilities.None); var hibernatedSessions = new HibernatedSessions(new List <HibernatedSessionInfo> { hibernatedSessionInfo }); await hibernatedSessions.WriteAsync(FileSystem, rootPath); var namedCacheRoots = new Dictionary <string, AbsolutePath> { { CacheName, rootPath } }; var grpcPort = PortExtensions.GetNextAvailablePort(); var grpcPortFileName = Guid.NewGuid().ToString(); var configuration = new ServiceConfiguration(namedCacheRoots, rootPath, MaxConnections, GracefulShutdownSeconds, grpcPort, grpcPortFileName); var storeConfig = ContentStoreConfiguration.CreateWithMaxSizeQuotaMB(1); Func <AbsolutePath, IContentStore> contentStoreFactory = (path) => new FileSystemContentStore( FileSystem, SystemClock.Instance, directory.Path, new ConfigurationModel(storeConfig)); var localContentServerConfiguration = new LocalServerConfiguration(configuration) { UnusedSessionHeartbeatTimeout = TimeSpan.FromSeconds(TimeoutSecs), RequestCallTokensPerCompletionQueue = 10, }; using (var server = new LocalContentServer(FileSystem, Logger, scenario, contentStoreFactory, localContentServerConfiguration)) { var r1 = await server.StartupAsync(context); r1.ShouldBeSuccess(); var beforeIds = server.GetSessionIds(); beforeIds.Should().Contain(SessionId); // Wait one period to ensure that it times out, another to ensure that the checker finds it, and another to give it time to release it. await Task.Delay(TimeSpan.FromSeconds(TimeoutSecs * 3)); var afterIds = server.GetSessionIds(); afterIds.Count.Should().Be(0); var r2 = await server.ShutdownAsync(context); r2.ShouldBeSuccess(); } } }