public async Task DiagnosticsTests() { TestServerType serverType = TestServerType.OnPrem; SqlTestDb.CreateNew(serverType, doNotCleanupDb: true, databaseName: Common.PerfTestDatabaseName, query: Scripts.CreateDatabaseObjectsQuery); using (TestServiceDriverProvider testService = new TestServiceDriverProvider()) using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile()) { await testService.ConnectForQuery(serverType, Scripts.TestDbSimpleSelectQuery, queryTempFile.FilePath, Common.PerfTestDatabaseName); Thread.Sleep(500); var contentChanges = new TextDocumentChangeEvent[1]; contentChanges[0] = new TextDocumentChangeEvent() { Range = new Range { Start = new Position { Line = 0, Character = 5 }, End = new Position { Line = 0, Character = 6 } }, RangeLength = 1, Text = "z" }; DidChangeTextDocumentParams changeParams = new DidChangeTextDocumentParams { ContentChanges = contentChanges, TextDocument = new VersionedTextDocumentIdentifier { Version = 2, Uri = queryTempFile.FilePath } }; TestTimer timer = new TestTimer() { PrintResult = true }; await testService.RequestChangeTextDocumentNotification(changeParams); await testService.ExecuteWithTimeout(timer, 60000, async() => { var completeEvent = await testService.Driver.WaitForEvent(PublishDiagnosticsNotification.Type, 15000); return(completeEvent?.Diagnostics != null && completeEvent.Diagnostics.Length > 0); }); await testService.Disconnect(queryTempFile.FilePath); } }
public async Task DiagnosticsTests() { using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile()) using (TestServiceDriverProvider testService = new TestServiceDriverProvider()) { bool connected = await testService.Connect(TestServerType.OnPrem, queryTempFile.FilePath); Assert.True(connected, "Connection was not successful"); Thread.Sleep(500); string query = "SELECT *** FROM sys.objects"; DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification { TextDocument = new TextDocumentItem { Uri = queryTempFile.FilePath, LanguageId = "enu", Version = 1, Text = query } }; await testService.RequestOpenDocumentNotification(openParams); Thread.Sleep(100); var contentChanges = new TextDocumentChangeEvent[1]; contentChanges[0] = new TextDocumentChangeEvent { Range = new Range { Start = new Position { Line = 0, Character = 5 }, End = new Position { Line = 0, Character = 6 } }, RangeLength = 1, Text = "z" }; DidChangeTextDocumentParams changeParams = new DidChangeTextDocumentParams() { ContentChanges = contentChanges, TextDocument = new VersionedTextDocumentIdentifier() { Version = 2, Uri = queryTempFile.FilePath } }; await testService.RequestChangeTextDocumentNotification(changeParams); Thread.Sleep(100); contentChanges[0] = new TextDocumentChangeEvent { Range = new Range { Start = new Position { Line = 0, Character = 5 }, End = new Position { Line = 0, Character = 6 } }, RangeLength = 1, Text = "t" }; changeParams = new DidChangeTextDocumentParams { ContentChanges = contentChanges, TextDocument = new VersionedTextDocumentIdentifier { Version = 3, Uri = queryTempFile.FilePath } }; await testService.RequestChangeTextDocumentNotification(changeParams); Thread.Sleep(2500); await testService.Disconnect(queryTempFile.FilePath); } }
/// <summary> /// Simulate typing by a user to stress test the language service /// </summary> //[Fact] public async Task TestLanguageService() { const string textToType = "SELECT * FROM sys.objects GO " + "CREATE TABLE MyTable(" + "FirstName CHAR," + "LastName CHAR," + "DateOfBirth DATETIME," + "CONSTRAINT MyTableConstraint UNIQUE (FirstName, LastName, DateOfBirth)) GO " + "INSERT INTO MyTable (FirstName, LastName, DateOfBirth) VALUES ('John', 'Doe', '19800101') GO " + "SELECT * FROM MyTable GO " + "ALTER TABLE MyTable DROP CONSTRAINT MyTableConstraint GO " + "DROP TABLE MyTable GO "; using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile()) using (TestServiceDriverProvider testService = new TestServiceDriverProvider()) { // Connect bool connected = await testService.Connect(TestServerType.OnPrem, string.Empty, queryTempFile.FilePath); Assert.True(connected, "Connection was not successful"); Thread.Sleep(10000); // Wait for intellisense to warm up // Simulate typing Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); int version = 1; while (stopwatch.Elapsed < TimeSpan.FromMinutes(60)) { for (int i = 0; i < textToType.Length; i++) { System.IO.File.WriteAllText(queryTempFile.FilePath, textToType.Substring(0, i + 1)); var contentChanges = new TextDocumentChangeEvent[1]; contentChanges[0] = new TextDocumentChangeEvent() { Range = new Range() { Start = new Position() { Line = 0, Character = i }, End = new Position() { Line = 0, Character = i } }, RangeLength = 1, Text = textToType.Substring(i, 1) }; DidChangeTextDocumentParams changeParams = new DidChangeTextDocumentParams() { ContentChanges = contentChanges, TextDocument = new VersionedTextDocumentIdentifier() { Version = ++version, Uri = queryTempFile.FilePath } }; await testService.RequestChangeTextDocumentNotification(changeParams); Thread.Sleep(50); // If we just typed a space, request/resolve completion if (textToType[i] == ' ') { var completions = await testService.RequestCompletion(queryTempFile.FilePath, textToType.Substring(0, i + 1), 0, i + 1); Assert.True(completions != null && completions.Length > 0, "Completion items list was null or empty"); Thread.Sleep(50); var item = await testService.RequestResolveCompletion(completions[0]); Assert.NotNull(item); } } // Clear the text document System.IO.File.WriteAllText(queryTempFile.FilePath, ""); var contentChanges2 = new TextDocumentChangeEvent[1]; contentChanges2[0] = new TextDocumentChangeEvent() { Range = new Range() { Start = new Position() { Line = 0, Character = 0 }, End = new Position() { Line = 0, Character = textToType.Length - 1 } }, RangeLength = textToType.Length, Text = "" }; DidChangeTextDocumentParams changeParams2 = new DidChangeTextDocumentParams() { ContentChanges = contentChanges2, TextDocument = new VersionedTextDocumentIdentifier() { Version = ++version, Uri = queryTempFile.FilePath } }; await testService.RequestChangeTextDocumentNotification(changeParams2); } await testService.Disconnect(queryTempFile.FilePath); } }