Skip to content

Commit e5a4957

Browse files
gabrielfeoclayburn
andauthored
Improve examples testing (#309)
- Simplify queries to make it easier to test against fresh instances, e.g. with no builds tagged for `tag:local`. - Ensure examples fail if 0 builds. Before, script and project examples would skip code such as `List.map` logic, hiding potential issues when testing. The notebook example would fail later in the plotting step with a non-obvious message: ``` java.lang.IllegalStateException: Column 'count' not found among [tasks]. ``` --------- Co-authored-by: Clay Johnson <cjohnson@gradle.com>
1 parent 92e4a93 commit e5a4957

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

examples/example-notebooks/MostFrequentBuilds.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,15 @@
114114
"val builds: List<GradleAttributes> = runBlocking {\n",
115115
" api.buildsApi.getBuildsFlow(\n",
116116
" fromInstant = 0,\n",
117-
" query = \"\"\"buildStartTime>-7d tag:local\"\"\",\n",
117+
" query = \"\"\"buildStartTime>-7d\"\"\",\n",
118118
" models = listOf(BuildModelName.gradleAttributes),\n",
119119
" ).map {\n",
120120
" it.models!!.gradleAttributes!!.model!!\n",
121121
" }.toList(LinkedList())\n",
122122
"}\n",
123123
"\n",
124-
"println(\"${builds.size} builds\")"
124+
"println(\"${builds.size} builds\")\n",
125+
"check(builds.isNotEmpty()) { \"No builds found. Adjust query and try again.\" }"
125126
]
126127
},
127128
{

examples/example-project/src/main/kotlin/com/gabrielfeo/develocity/api/example/analysis/MostFrequentBuilds.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ suspend fun mostFrequentBuilds(
2727
// Fetch builds from the API
2828
val builds: List<GradleAttributes> = api.getBuildsFlow(
2929
fromInstant = 0,
30-
query = """buildStartTime>$startTime tag:local""",
30+
query = """buildStartTime>$startTime""",
3131
models = listOf(BuildModelName.gradleAttributes),
3232
).map {
3333
it.models!!.gradleAttributes!!.model!!
3434
}.toList(LinkedList())
3535

3636
// Process builds and count how many times each was invoked
37+
check(builds.isNotEmpty()) { "No builds found. Adjust query and try again." }
3738
val buildCounts = builds.groupBy { build ->
3839
val tasks = build.requestedTasks.joinToString(" ").trim(':')
3940
tasks.ifBlank { "IDE sync" }

examples/example-scripts/example-script.main.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ val api = DevelocityApi.newInstance()
3838
val builds: List<GradleAttributes> = runBlocking {
3939
api.buildsApi.getBuildsFlow(
4040
fromInstant = 0,
41-
query = """buildStartTime>-7d tag:local""",
41+
query = """buildStartTime>-7d""",
4242
models = listOf(BuildModelName.gradleAttributes),
4343
).map {
4444
it.models!!.gradleAttributes!!.model!!
4545
}.toList(LinkedList())
4646
}
4747

4848
// Process builds and count how many times each was invoked
49+
check(builds.isNotEmpty()) { "No builds found. Adjust query and try again." }
4950
val buildCounts = builds.groupBy { build ->
5051
val tasks = build.requestedTasks.joinToString(" ").trim(':')
5152
tasks.ifBlank { "IDE sync" }

library/src/integrationTest/kotlin/com/gabrielfeo/develocity/api/DevelocityApiIntegrationTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class DevelocityApiIntegrationTest {
2323
val builds = api.buildsApi.getBuilds(
2424
since = 0,
2525
maxBuilds = 5,
26-
query = """tag:local value:"Email=gabriel.feo*""""
26+
query = """buildStartTime>-7d""""
2727
)
2828
assertEquals(5, builds.size)
2929
api.shutdown()

0 commit comments

Comments
 (0)