Exemple #1
0
        public virtual void Dispose()
        {
            GC.SuppressFinalize(this);

            if (_concurrentTestsSemaphoreTaken.Lower())
            {
                ConcurrentTestsSemaphore.Release();
            }

            var exceptionAggregator = new ExceptionAggregator("Could not dispose test");

            Dispose(exceptionAggregator);

            if (_localServer != null && _localServer != _globalServer)
            {
                exceptionAggregator.Execute(() =>
                {
                    _localServer.Dispose();
                    _localServer = null;
                });
            }

            RavenTestHelper.DeletePaths(_localPathsToDelete, exceptionAggregator);

            exceptionAggregator.ThrowIfNeeded();
        }
Exemple #2
0
        private void UnloadServer(AssemblyLoadContext obj)
        {
            try
            {
                lock (ServerLocker)
                {
                    var copyGlobalServer = _globalServer;
                    _globalServer = null;
                    if (copyGlobalServer == null)
                    {
                        return;
                    }
                    copyGlobalServer.Dispose();

                    GC.Collect(2);
                    GC.WaitForPendingFinalizers();

                    var exceptionAggregator = new ExceptionAggregator("Failed to cleanup test databases");

                    RavenTestHelper.DeletePaths(GlobalPathsToDelete, exceptionAggregator);

                    exceptionAggregator.ThrowIfNeeded();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
        public virtual void Dispose()
        {
            GC.SuppressFinalize(this);

            GC.Collect(2);
            GC.WaitForPendingFinalizers();

#pragma warning disable 618 // Yes, I know this is obselete
            var alreadyHasException = Marshal.GetExceptionCode() == 0;
#pragma warning restore 618
            var exceptionAggregator = new ExceptionAggregator("Could not dispose test");

            RavenTestHelper.DeletePaths(_pathsToDelete, exceptionAggregator);
            if (alreadyHasException == false)
            {
                exceptionAggregator.ThrowIfNeeded();
            }
        }
Exemple #4
0
        private static void UnloadServer(AssemblyLoadContext obj)
        {
            try
            {
                lock (ServerLocker)
                {
                    var copyGlobalServer = _globalServer;
                    _globalServer = null;
                    if (copyGlobalServer == null)
                    {
                        return;
                    }

                    try
                    {
                        using (copyGlobalServer.ServerStore.ContextPool.AllocateOperationContext(out TransactionOperationContext context))
                            using (context.OpenReadTransaction())
                            {
                                var databases = copyGlobalServer
                                                .ServerStore
                                                .Cluster
                                                .ItemsStartingWith(context, Constants.Documents.Prefix, 0, int.MaxValue)
                                                .ToList();

                                if (databases.Count > 0)
                                {
                                    var sb = new StringBuilder();
                                    sb.AppendLine("List of non-deleted databases:");

                                    foreach (var t in databases)
                                    {
                                        var databaseName = t.ItemName.Substring(Constants.Documents.Prefix.Length);

                                        try
                                        {
                                            AsyncHelpers.RunSync(() => copyGlobalServer.ServerStore.DeleteDatabaseAsync(databaseName, hardDelete: true, null, Guid.NewGuid().ToString()));
                                        }
                                        catch (Exception)
                                        {
                                            // ignored
                                        }

                                        sb
                                        .Append("- ")
                                        .AppendLine(databaseName);
                                    }

                                    Console.WriteLine(sb.ToString());
                                }
                            }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"Could not retrieve list of non-deleted databases. Exception: {e}");
                    }

                    copyGlobalServer.Dispose();

                    GC.Collect(2);
                    GC.WaitForPendingFinalizers();

                    var exceptionAggregator = new ExceptionAggregator("Failed to cleanup test databases");

                    RavenTestHelper.DeletePaths(GlobalPathsToDelete, exceptionAggregator);

                    exceptionAggregator.ThrowIfNeeded();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                CheckServerLeak();
            }
        }