On the Flakiness of LLM-Generated Tests for Industrial and Open-Source Database Management Systems
This study investigates the flakiness of LLM-generated tests for four database management systems, revealing that such tests exhibit a slightly higher flakiness rate than existing ones primarily due to reliance on non-guaranteed execution orders, and that LLMs often propagate existing flakiness patterns from their prompts, particularly in closed-source environments.
Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
Imagine you are hiring a very talented, well-read robot assistant to help you write safety checks for a complex machine, like a database that stores all your company's important information. You give the robot a few examples of how you write these checks, and it starts churning out hundreds of new ones.
This paper is like a report card on how reliable those robot-written checks actually are. The researchers wanted to know: Do these robot-written tests work consistently, or do they act "flaky"?
What is a "Flaky" Test?
Think of a "flaky" test like a coin flip that you expect to be heads every time.
- A normal test: You run it, and it says "Pass." You run it again, and it says "Pass." It's reliable.
- A flaky test: You run it, and it says "Pass." You run it again, and it says "Fail." You run it a third time, and it says "Pass" again.
This is a nightmare for engineers. If a test fails randomly, they can't tell if the machine is actually broken or if the test just had a bad day. It wastes time and makes people lose trust in the safety checks.
The Experiment: The Robot vs. The Real World
The researchers set up an experiment with four different "machines" (databases):
- SAP HANA: A massive, complex, closed-source industrial database (like a secret, high-tech vault).
- MySQL, SQLite, and DuckDB: Popular open-source databases (like well-known, public blueprints).
They used two different "robot brains" (Large Language Models, or LLMs): GPT-4o and Mistral. They asked these robots to look at existing tests and write new ones to cover more scenarios (a process called "test amplification").
The Big Findings
1. The Robot is a bit more "jittery" than the humans.
The researchers found that the tests written by the robots were slightly more likely to be flaky than the tests written by human engineers. While human-written tests were mostly solid, the robot's tests had a higher chance of failing randomly.
2. The "Order" Confusion (The Main Culprit).
The biggest reason the robot tests were flaky? Confusion about order.
Imagine you ask a robot to list the top 3 students in a class. If you don't tell it how to sort them (by grade, by name, by height), the robot might give you a different list every time it runs.
- The Human Mistake: The robot wrote tests that assumed the database would always return results in a specific order (like a list sorted A-Z).
- The Reality: Databases often return results in a random order unless you explicitly tell them to sort them.
- The Result: The test would pass one time (because the random order happened to match the robot's guess) and fail the next time (because the order changed). This happened in 63% of the flaky robot tests.
3. The "Copycat" Effect (Flakiness Transfer).
This is the most interesting part. The researchers decided to play a trick. They took an existing test that was already flaky (a bad example) and fed it to the robot as an example of how to write a test.
- The Result: The robot didn't just copy the code; it copied the bad habit. It started writing new tests that were flaky in the exact same way.
- The Difference: The robot did this much more often with the SAP HANA (the secret industrial database) than with the open-source ones. Why? Because the robot had never seen SAP HANA code before in its training. It relied heavily on the examples you gave it, even if those examples were broken. With open-source databases, the robot had seen similar code before, so it was a bit more independent.
4. The Compilation Struggle.
For the complex, closed-source SAP HANA, the robot struggled to write code that even compiled (worked as a program) about half the time. It's like the robot trying to write instructions for a car engine it has never seen before, using only a few diagrams you gave it. It got confused and made syntax errors.
The Takeaway
The paper concludes that while AI is great at writing code that looks natural and human-like, it has a blind spot: it doesn't always understand the hidden rules of the system it's testing.
- The "Order" Trap: It often forgets that databases don't guarantee the order of results unless told otherwise.
- The "Bad Example" Trap: If you show the AI a flaky test, it will likely copy that flakiness, especially if it doesn't know the system well.
The Advice: Before you let an AI write your safety checks, you need to make sure your existing checks are rock-solid. If you feed the AI bad examples, it will learn bad habits. Also, you need to give the AI very specific instructions about how the system works, because it can't guess the hidden rules on its own.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.