Example #1
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));
                                        }
                                        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);
            }
        }
Example #2
0
        static unsafe TestBase()
        {
            IgnoreProcessorAffinityChanges(ignore: true);
            LicenseManager.AddLicenseStatusToLicenseLimitsException = true;
            RachisStateMachine.EnableDebugLongCommit = true;

            NativeMemory.GetCurrentUnmanagedThreadId = () => (ulong)Pal.rvn_get_current_thread_id();
            Lucene.Net.Util.UnmanagedStringArray.Segment.AllocateMemory = NativeMemory.AllocateMemory;
            Lucene.Net.Util.UnmanagedStringArray.Segment.FreeMemory     = NativeMemory.Free;

            BackupTask.DateTimeFormat           = "yyyy-MM-dd-HH-mm-ss-fffffff";
            RestorePointsBase.BackupFolderRegex = new Regex(@"([0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{2}-[0-9]{2}(-[0-9]{2}-[0-9]{7})?).ravendb-(.+)-([A-Za-z]+)-(.+)$", RegexOptions.Compiled);
            RestorePointsBase.FileNameRegex     = new Regex(@"([0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{2}-[0-9]{2}(-[0-9]{2}-[0-9]{7})?)", RegexOptions.Compiled);

            var packagesPath = new PathSetting(RavenTestHelper.NewDataPath("NuGetPackages", 0, forceCreateDir: true));

            GlobalPathsToDelete.Add(packagesPath.FullPath);
            MultiSourceNuGetFetcher.Instance.Initialize(packagesPath, "https://api.nuget.org/v3/index.json");

#if DEBUG2
            TaskScheduler.UnobservedTaskException += (sender, args) =>
            {
                if (args.Observed)
                {
                    return;
                }

                var e = args.Exception.ExtractSingleInnerException();

                var sb = new StringBuilder();
                sb.AppendLine("===== UNOBSERVED TASK EXCEPTION =====");
                sb.AppendLine(e.ExceptionToString(null));
                sb.AppendLine("=====================================");

                Console.WriteLine(sb.ToString());
            };
#endif
            if (PlatformDetails.RunningOnPosix == false &&
                PlatformDetails.Is32Bits) // RavenDB-13655
            {
                ThreadPool.SetMinThreads(25, 25);
                ThreadPool.SetMaxThreads(125, 125);
            }
            else
            {
                ThreadPool.SetMinThreads(250, 250);
            }

            RequestExecutor.RemoteCertificateValidationCallback += (sender, cert, chain, errors) => true;

            var maxNumberOfConcurrentTests = Math.Max(ProcessorInfo.ProcessorCount / 2, 2);

            if (int.TryParse(Environment.GetEnvironmentVariable("RAVEN_MAX_RUNNING_TESTS"), out var maxRunningTests))
            {
                maxNumberOfConcurrentTests = maxRunningTests;
            }
            else
            {
                var fileInfo = new FileInfo(XunitConfigurationFile);
                if (fileInfo.Exists)
                {
                    using (var file = File.OpenRead(XunitConfigurationFile))
                        using (var sr = new StreamReader(file))
                        {
                            var json = JObject.Parse(sr.ReadToEnd());

                            if (json.TryGetValue("maxRunningTests", out var testsToken))
                            {
                                maxNumberOfConcurrentTests = testsToken.Value <int>();
                            }
                            else if (json.TryGetValue("maxParallelThreads", out var threadsToken))
                            {
                                maxNumberOfConcurrentTests = threadsToken.Value <int>();
                            }
                        }
                }
            }

            Console.WriteLine("Max number of concurrent tests is: " + maxNumberOfConcurrentTests);
            ConcurrentTestsSemaphore = new SemaphoreSlim(maxNumberOfConcurrentTests, maxNumberOfConcurrentTests);
        }