summaryrefslogtreecommitdiff
path: root/logcat
diff options
context:
space:
mode:
authorAlon Albert <aalbert@google.com>2022-07-27 12:55:28 -0700
committerTreeHugger Robot <treehugger-gerrit@google.com>2022-07-27 20:35:46 +0000
commit17798fb623139acef8766b3e7981540d728cb969 (patch)
tree945aae224d1bd3b107cae596f654e782a134481d /logcat
parent43d300cc5756ed6110f46fca2659bdb8563aed75 (diff)
downloadidea-17798fb623139acef8766b3e7981540d728cb969.tar.gz
Fix Flaky Test
There are 2 issues with these tests: 1. The preset filter does not actually match the emitted logs. This causes the text in the document to get reset when the filter is applied - which happens in the background. 2. The code wasn't synchronized to allow the filter to apply. So we add a log message that will be removed by the filter and wait for that to happen first. Bug: N/A Test: Self Change-Id: I9958c6ef0e74cff7871f5bdb8811acb07ae064a0
Diffstat (limited to 'logcat')
-rw-r--r--logcat/testSrc/com/android/tools/idea/logcat/LogcatMainPanelTest.kt41
1 files changed, 22 insertions, 19 deletions
diff --git a/logcat/testSrc/com/android/tools/idea/logcat/LogcatMainPanelTest.kt b/logcat/testSrc/com/android/tools/idea/logcat/LogcatMainPanelTest.kt
index e7b9dc9df51..c17c0662507 100644
--- a/logcat/testSrc/com/android/tools/idea/logcat/LogcatMainPanelTest.kt
+++ b/logcat/testSrc/com/android/tools/idea/logcat/LogcatMainPanelTest.kt
@@ -45,6 +45,7 @@ import com.android.tools.idea.logcat.filters.StringFilter
import com.android.tools.idea.logcat.folding.FoldingDetector
import com.android.tools.idea.logcat.hyperlinks.HyperlinkDetector
import com.android.tools.idea.logcat.message.LogLevel
+import com.android.tools.idea.logcat.message.LogLevel.DEBUG
import com.android.tools.idea.logcat.message.LogLevel.INFO
import com.android.tools.idea.logcat.message.LogLevel.WARN
import com.android.tools.idea.logcat.message.LogcatHeader
@@ -883,21 +884,23 @@ class LogcatMainPanelTest {
val logcatMainPanel = runInEdtAndGet {
logcatMainPanel().apply {
size = Dimension(100, 100)
- headerPanel.filter = "foo"
}
}
val fakeUi = runInEdtAndGet { FakeUi(logcatMainPanel.editor.contentComponent, createFakeWindow = true) }
-
- logcatMainPanel.messageProcessor.appendMessages(listOf(
- LogcatMessage(LogcatHeader(INFO, 1, 2, "app2", "", "tag2", Instant.ofEpochMilli(1000)), "message2"),
+ logcatMainPanel.processMessages(listOf(
+ LogcatMessage(LogcatHeader(INFO, 1, 2, "app1", "", "tag1", Instant.ofEpochMilli(1000)), "foo"),
+ LogcatMessage(LogcatHeader(INFO, 1, 2, "app2", "", "tag2", Instant.ofEpochMilli(1000)), "bar"),
))
-
+ runInEdtAndWait { logcatMainPanel.setFilter("foo") }
+ waitForCondition { logcatMainPanel.editor.document.text.endsWith("foo\n") }
logcatMainPanel.messageProcessor.onIdle {
runInEdtAndWait {
- val offset = logcatMainPanel.editor.document.immutableCharSequence.indexOf("app2")
+ val offset = logcatMainPanel.editor.document.immutableCharSequence.indexOf("app1")
val point = logcatMainPanel.editor.offsetToXY(offset)
+
fakeUi.mouse.click(point.x + 1, point.y + 1, CTRL_LEFT)
- assertThat(logcatMainPanel.headerPanel.filter).isEqualTo("foo package:app2")
+
+ assertThat(logcatMainPanel.headerPanel.filter).isEqualTo("foo package:app1")
}
}
}
@@ -907,21 +910,21 @@ class LogcatMainPanelTest {
val logcatMainPanel = runInEdtAndGet {
logcatMainPanel().apply {
size = Dimension(100, 100)
- headerPanel.filter = "package:mine level:INFO"
}
}
val fakeUi = runInEdtAndGet { FakeUi(logcatMainPanel.editor.contentComponent, createFakeWindow = true) }
-
- logcatMainPanel.messageProcessor.appendMessages(listOf(
- LogcatMessage(LogcatHeader(INFO, 1, 2, "app2", "", "tag2", Instant.ofEpochMilli(1000)), "message2"),
+ logcatMainPanel.processMessages(listOf(
+ LogcatMessage(LogcatHeader(INFO, 1, 2, "app1", "", "tag1", Instant.ofEpochMilli(1000)), "foo"),
+ LogcatMessage(LogcatHeader(DEBUG, 1, 2, "app2", "", "tag2", Instant.ofEpochMilli(1000)), "bar"),
))
-
+ runInEdtAndWait { logcatMainPanel.setFilter("foo level:INFO") }
+ waitForCondition { logcatMainPanel.editor.document.text.endsWith("foo\n") }
logcatMainPanel.messageProcessor.onIdle {
runInEdtAndWait {
val offset = logcatMainPanel.editor.document.immutableCharSequence.indexOf(" I ")
val point = logcatMainPanel.editor.offsetToXY(offset)
fakeUi.mouse.click(point.x + 1, point.y + 1, CTRL_LEFT)
- assertThat(logcatMainPanel.headerPanel.filter).isEqualTo("package:mine")
+ assertThat(logcatMainPanel.headerPanel.filter).isEqualTo("foo")
}
}
}
@@ -931,21 +934,21 @@ class LogcatMainPanelTest {
val logcatMainPanel = runInEdtAndGet {
logcatMainPanel().apply {
size = Dimension(100, 100)
- headerPanel.filter = "level:INFO package:mine level:INFO"
}
}
val fakeUi = runInEdtAndGet { FakeUi(logcatMainPanel.editor.contentComponent, createFakeWindow = true) }
-
- logcatMainPanel.messageProcessor.appendMessages(listOf(
- LogcatMessage(LogcatHeader(INFO, 1, 2, "app2", "", "tag2", Instant.ofEpochMilli(1000)), "message2"),
+ logcatMainPanel.processMessages(listOf(
+ LogcatMessage(LogcatHeader(INFO, 1, 2, "app1", "", "tag1", Instant.ofEpochMilli(1000)), "foo"),
+ LogcatMessage(LogcatHeader(DEBUG, 1, 2, "app2", "", "tag2", Instant.ofEpochMilli(1000)), "bar"),
))
-
+ runInEdtAndWait { logcatMainPanel.setFilter(" level:INFO foo level:INFO") }
+ waitForCondition { logcatMainPanel.editor.document.text.endsWith("foo\n") }
logcatMainPanel.messageProcessor.onIdle {
runInEdtAndWait {
val offset = logcatMainPanel.editor.document.immutableCharSequence.indexOf(" I ")
val point = logcatMainPanel.editor.offsetToXY(offset)
fakeUi.mouse.click(point.x + 1, point.y + 1, CTRL_LEFT)
- assertThat(logcatMainPanel.headerPanel.filter).isEqualTo("package:mine")
+ assertThat(logcatMainPanel.headerPanel.filter).isEqualTo("foo")
}
}
}