The test “ensure continuous stream is being used“ in KafkaContinuousTestquickly checks the actual type of the execution, and stop the query. Stopping the streaming query in continuous mode is done by interrupting query execution thread and join indefinitely.
In parallel, started streaming query is going to generate execution plan, including running optimizer. Some parts of SessionState can be built at that time, as they are defined as lazy. The problem is, some of them seem to be able to “swallow” the InterruptedException and let the thread run continuously.
That said, the query can’t indicate whether there is a request on stopping query, so the query won’t stop.