-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathDatabaseDiagnosticsTest.java
More file actions
157 lines (134 loc) · 5.39 KB
/
DatabaseDiagnosticsTest.java
File metadata and controls
157 lines (134 loc) · 5.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* Copyright (c) 2013-2019 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.labkey.test.tests;
import org.junit.Assume;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.labkey.test.BaseWebDriverTest;
import org.labkey.test.Locator;
import org.labkey.test.Locators;
import org.labkey.test.TestFileUtils;
import org.labkey.test.TestProperties;
import org.labkey.test.WebTestHelper;
import org.labkey.test.categories.BVT;
import org.labkey.test.categories.CustomModules;
import org.labkey.test.categories.Daily;
import org.labkey.test.categories.Git;
import org.labkey.test.io.Grep;
import org.labkey.test.pages.core.admin.SiteValidationPage;
import org.labkey.test.pages.pipeline.PipelineStatusDetailsPage;
import org.labkey.test.util.AttachmentHelper;
import org.labkey.test.util.Maps;
import org.labkey.test.util.Order;
import org.labkey.test.util.PasswordUtil;
import org.labkey.test.util.PipelineStatusTable;
import org.labkey.test.util.TextSearcher;
import org.openqa.selenium.WebElement;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import static org.junit.Assert.assertTrue;
/** Intended to be run at the end of suites to do some extra validation, without adding much extra overhead. */
@Category({BVT.class, Daily.class, Git.class, CustomModules.class})
@Order(1)
@BaseWebDriverTest.ClassTimeout(minutes = 20)
public class DatabaseDiagnosticsTest extends BaseWebDriverTest
{
@Override
protected String getProjectName()
{
return null;
}
@Test
public void validateDomainsTest()
{
goToAdminConsole().goToSettingsSection();
clickAndWait(Locator.linkWithText("check database"));
click(Locator.linkWithText("Validate"));
PipelineStatusTable statusTable = new PipelineStatusTable(this);
statusTable.clickStatusLink(0)
.waitForComplete(300_000)
.assertLogTextContains("Check complete, 0 errors found");
}
@Test
public void testSiteValidator()
{
SiteValidationPage validationPage = goToAdminConsole().clickSiteValidation();
validationPage.setAllValidators(true);
// Validate projects and subfolders
validationPage.setWholeSite(true);
PipelineStatusDetailsPage jobPage = validationPage.clickValidateInBackground();
jobPage.waitForComplete(300_000)
.assertLogTextContains("Site validation complete");
jobPage.clickDataLink();
assertNoLabKeyErrors();
TextSearcher textSearcher = new TextSearcher(getText(Locators.bodyPanel()));
assertTextPresent(textSearcher,
"Site Level Validation Results", "Folder Validation Results",
"Module: Core", "Permissions Validator", "Display Format Validator",
"Module: Pipeline", "Pipeline Validator");
assertTextNotPresent(textSearcher, "Errors:");
}
@Test
public void databaseCheckTest()
{
// This can take very long depending on what modules are present
beginAt(WebTestHelper.buildURL("admin", "doCheck"), 600000);
waitForText(60000, "Database Consistency checker complete");
assertTextNotPresent("ERROR");
}
@Test
public void testTomcatLogs() throws Exception
{
Assume.assumeFalse("Can't check log files on remote server", TestProperties.isServerRemote());
File logDir = TestFileUtils.getServerLogDir();
assertTrue("Server log directory does not exist: " + logDir, logDir.isDirectory());
File[] logs = logDir.listFiles();
Map<File, Integer> contaminatedLogs = Grep.grep(PasswordUtil.getPassword(), logs);
Map<String, String> failureFiles = new TreeMap<>();
contaminatedLogs.keySet().forEach(
file -> failureFiles.put(file.getName(), "line " + contaminatedLogs.get(file)));
assertTrue(String.format("These tomcat logs (in %s) contained unwanted text [%s]:\n%s",
logDir.getAbsolutePath(), PasswordUtil.getPassword(), failureFiles),
failureFiles.isEmpty());
}
@Test
public void collectActionExceptions()
{
beginAt(WebTestHelper.buildURL("admin", "actions", Maps.of("tabId", "exceptions")));
WebElement exceptionCount = waitForElement(Locator.id("exceptionCount"));
if (!"no exceptions".equals(exceptionCount.getText()))
getArtifactCollector().dumpPageSnapshot("exceptions", null);
}
@Test
public void testOrphanedAttachments()
{
int orphanCount = AttachmentHelper.logOrphanedAttachments();
if (orphanCount > 0)
log("Orphaned attachments: " + orphanCount);
}
@Override
public List<String> getAssociatedModules()
{
return Arrays.asList("admin");
}
@Override public BrowserType bestBrowser()
{
return BrowserType.CHROME;
}
}