Skip to content

Commit

Permalink
Improve examples testing (#309)
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
gabrielfeo and clayburn authored Sep 11, 2024
1 parent 92e4a93 commit e5a4957
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions examples/example-notebooks/MostFrequentBuilds.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,15 @@
"val builds: List<GradleAttributes> = runBlocking {\n",
" api.buildsApi.getBuildsFlow(\n",
" fromInstant = 0,\n",
" query = \"\"\"buildStartTime>-7d tag:local\"\"\",\n",
" query = \"\"\"buildStartTime>-7d\"\"\",\n",
" models = listOf(BuildModelName.gradleAttributes),\n",
" ).map {\n",
" it.models!!.gradleAttributes!!.model!!\n",
" }.toList(LinkedList())\n",
"}\n",
"\n",
"println(\"${builds.size} builds\")"
"println(\"${builds.size} builds\")\n",
"check(builds.isNotEmpty()) { \"No builds found. Adjust query and try again.\" }"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ suspend fun mostFrequentBuilds(
// Fetch builds from the API
val builds: List<GradleAttributes> = api.getBuildsFlow(
fromInstant = 0,
query = """buildStartTime>$startTime tag:local""",
query = """buildStartTime>$startTime""",
models = listOf(BuildModelName.gradleAttributes),
).map {
it.models!!.gradleAttributes!!.model!!
}.toList(LinkedList())

// Process builds and count how many times each was invoked
check(builds.isNotEmpty()) { "No builds found. Adjust query and try again." }
val buildCounts = builds.groupBy { build ->
val tasks = build.requestedTasks.joinToString(" ").trim(':')
tasks.ifBlank { "IDE sync" }
Expand Down
3 changes: 2 additions & 1 deletion examples/example-scripts/example-script.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ val api = DevelocityApi.newInstance()
val builds: List<GradleAttributes> = runBlocking {
api.buildsApi.getBuildsFlow(
fromInstant = 0,
query = """buildStartTime>-7d tag:local""",
query = """buildStartTime>-7d""",
models = listOf(BuildModelName.gradleAttributes),
).map {
it.models!!.gradleAttributes!!.model!!
}.toList(LinkedList())
}

// Process builds and count how many times each was invoked
check(builds.isNotEmpty()) { "No builds found. Adjust query and try again." }
val buildCounts = builds.groupBy { build ->
val tasks = build.requestedTasks.joinToString(" ").trim(':')
tasks.ifBlank { "IDE sync" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DevelocityApiIntegrationTest {
val builds = api.buildsApi.getBuilds(
since = 0,
maxBuilds = 5,
query = """tag:local value:"Email=gabriel.feo*""""
query = """buildStartTime>-7d""""
)
assertEquals(5, builds.size)
api.shutdown()
Expand Down

0 comments on commit e5a4957

Please sign in to comment.