<commit_before>﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Tgstation.Server.Host;
using Tgstation.Server.Host.Configuration;
using Tgstation.Server.Host.Core;

namespace Tgstation.Server.Tests
{
	sealed class TestingServer : IServer, IDisposable
	{
		public Uri Url { get; }

		public string Directory { get; }

		public string UpdatePath { get; }

		public string DatabaseType { get; }

		public bool DumpOpenApiSpecpath { get; }

		public bool RestartRequested => realServer.RestartRequested;

		string[] args;

		IServer realServer;

		public TestingServer()
		{
			Directory = Environment.GetEnvironmentVariable("TGS4_TEST_TEMP_DIRECTORY");
			if (String.IsNullOrWhiteSpace(Directory))
			{
				Directory = Path.Combine(Path.GetTempPath(), "TGS4_INTEGRATION_TEST");
				if(System.IO.Directory.Exists(Directory))
					try
					{
						System.IO.Directory.Delete(Directory, true);
					}
					catch
					{
						Directory = Path.Combine(Directory, Guid.NewGuid().ToString());
					}
			}

			System.IO.Directory.CreateDirectory(Directory);
			const string UrlString = "http://localhost:5010";
			Url = new Uri(UrlString);

			//so we need a db
			//we have to rely on env vars
			DatabaseType = Environment.GetEnvironmentVariable("TGS4_TEST_DATABASE_TYPE");<commit_msg>Fix potential integration test crash<commit_after>﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Tgstation.Server.Host;
using Tgstation.Server.Host.Configuration;
using Tgstation.Server.Host.Core;

namespace Tgstation.Server.Tests
{
	sealed class TestingServer : IServer, IDisposable
	{
		public Uri Url { get; }

		public string Directory { get; }

		public string UpdatePath { get; }

		public string DatabaseType { get; }

		public bool DumpOpenApiSpecpath { get; }

		public bool RestartRequested => realServer.RestartRequested;

		string[] args;

		IServer realServer;

		public TestingServer()
		{
			Directory = Environment.GetEnvironmentVariable("TGS4_TEST_TEMP_DIRECTORY");
			if (String.IsNullOrWhiteSpace(Directory))
			{
				Directory = Path.Combine(Path.GetTempPath(), "TGS4_INTEGRATION_TEST");
				if (System.IO.Directory.Exists(Directory))
					try
					{
						System.IO.Directory.Delete(Directory, true);
					}
					catch { }

			}

			Directory = Path.Combine(Directory, Guid.NewGuid().ToString());
			System.IO.Directory.CreateDirectory(Directory);
			const string UrlString = "http://localhost:5010";
			Url = new Uri(UrlString);

			//so we need a db
			//we have to rely on env vars
			DatabaseType = Environment.GetEnvironmentVariable("TGS4_TEST_DATABASE_TYPE");
{'fraction_non_alphanumeric': 0.102880658436214, 'fraction_numerical': 0.004801097393689987, 'mean_word_length': 4.265342960288809, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5620048', 'n_tokens_mistral': 1035, 'n_tokens_neox': 866, 'n_words': 196}