@@ -92,6 +92,7 @@ public abstract class EsqlSpecTestCase extends ESRestTestCase {
9292 protected final CsvTestCase testCase ;
9393 protected final String instructions ;
9494 protected final Mode mode ;
95+ protected static Boolean supportsTook ;
9596
9697 public enum Mode {
9798 SYNC ,
@@ -272,7 +273,7 @@ protected final void doTest() throws Throwable {
272273 builder .tables (tables ());
273274 }
274275
275- Map <?, ?> prevTooks = tooks ();
276+ Map <?, ?> prevTooks = supportsTook () ? tooks () : null ;
276277 Map <String , Object > answer = runEsql (builder .query (testCase .query ), testCase .assertWarnings (deduplicateExactWarnings ()));
277278
278279 var expectedColumnsWithValues = loadCsvSpecValues (testCase .expectedResults );
@@ -290,9 +291,12 @@ protected final void doTest() throws Throwable {
290291
291292 assertResults (expectedColumnsWithValues , actualColumns , actualValues , testCase .ignoreOrder , logger );
292293
293- long took = ((Number ) answer .get ("took" )).longValue ();
294- int prevTookHisto = ((Number ) prevTooks .remove (tookKey (took ))).intValue ();
295- assertMap (tooks (), matchesMap (prevTooks ).entry (tookKey (took ), prevTookHisto + 1 ));
294+ if (supportsTook ()) {
295+ LOGGER .info ("checking took incremented from {}" , prevTooks );
296+ long took = ((Number ) answer .get ("took" )).longValue ();
297+ int prevTookHisto = ((Number ) prevTooks .remove (tookKey (took ))).intValue ();
298+ assertMap (tooks (), matchesMap (prevTooks ).entry (tookKey (took ), prevTookHisto + 1 ));
299+ }
296300 }
297301
298302 private Map <?, ?> tooks () throws IOException {
@@ -486,6 +490,13 @@ private Map<String, Map<String, RestEsqlTestCase.TypeAndValues>> tables() {
486490 return tables ;
487491 }
488492
493+ protected boolean supportsTook () throws IOException {
494+ if (supportsTook == null ) {
495+ supportsTook = hasCapabilities (client (), List .of ("usage_contains_took" ));
496+ }
497+ return supportsTook ;
498+ }
499+
489500 private String tookKey (long took ) {
490501 if (took < 10 ) {
491502 return "lt_10ms" ;
0 commit comments