- 29.1 Three Grains of Rice
- 29.2 Understanding Has to Grow
- 29.3 First Day Automated Testing
- 29.4 Attempting to Get Automation Started
- 29.5 Struggling with (against) Management
- 29.6 Exploratory Test Automation: Database Record Locking
- 29.7 Lessons Learned from Test Automation in an Embedded Hardware-Software Computer Environment
- 29.8 The Contagious Clock
- 29.9 Flexibility of the Automation System
- 29.10 A Tale of Too Many Tools (and Not Enough Cross-Department Support)
- 29.11 A Success with a Surprising End
- 29.12 Cooperation Can Overcome Resource Limitations
- 29.13 An Automation Process for Large-Scale Success
- 29.14 Test Automation Isn't Always What It Seems
29.6 Exploratory Test Automation: Database Record Locking
Douglas Hoffman, United States
Consultant and speaker
Pre–World Wide Web (late 1980s), I was the quality assurance (QA) manager, test lead, and test architect for the second-largest relational database management system (RDBMS) software company at the time. Before landing the job, I got my bachelor’s degree in computer science, started out as a systems engineer, and had worked my way up into hands-on engineering services management (QA, tech support, sales support, and tech writing).
The company had about 300 employees, mostly in San Mateo, California. The relational database engine had evolved over more than 10 years and had a well-established, fairly stable codebase. At the time, the code had to be ported across 180 hardware/software platforms (most were variations of UNIX). The QA team was small (initially with a ratio of about 1:20 with developers, growing to ~1:5 over 18 months) and nearly completely focused on testing. Most new testers were recruited from other companies’ development organizations.
To support the large number of versions, the product was developed using internal switches to enable or disable different code functions. Therefore, most of the porting was done by selecting the proper combinations of switches. This meant that once features or bug fixes had been incorporated into the base code, the various ports would pour into QA.
Because the test team was small, we spent almost all our time running tests on the various platforms. Little time was available for design and implementation of tests for new features. A thorough test run for a new release on a platform could take 2 weeks, and the dozen testers could receive 150 versions in a few weeks. The management and technical challenges dealing with this situation are other case studies in themselves. This case study focuses on one particular exploratory automated test we created.
Unlike regression tests that do the same thing every time they are run, exploratory automated tests are automated tests that don’t have predetermined results built in; they create new conditions and inputs each time they’re run. Exploratory test automation is capable of finding bugs that were never specifically conceived of in advance. These are typically long-sequence tests and involve huge numbers of iterations because they are only limited by available computer resources.
29.6.1 The Case Study
Bug being sought: Errors in database record locking (failure to lock or release a lock on a record, table, or database).
When I took over the QA organization, the existing test cases were simple applications written in the various frontend languages, mostly our proprietary SQL. Most existing tests were applications and data sets collected from customers or scripts that verified bug fixes. Automation was achieved using a simple shell script that walked through the directories containing the tests and sequentially launched them. Most of the testers’ efforts were in analyzing the results and tweaking the tests to conform with nuances on the various platforms.
One area of concern that wasn’t well tested using our regression tests was record locking. A few intermittent bugs that locked up the programs or clobbered data had been found in the field. The locking mechanism was complex because of the distributed nature of the database. For example:
- Parts of the database might be replicated and the “master” copy moved around as requests were made.
- Different parts of the database needed to communicate about actions before they could be completed.
- Requests could occur simultaneously.
- Common data could be updated by multiple users.
- One user’s request for exclusive access (e.g., to update part of a record) could cause some other users’ requests to wait.
- User requests for nonexclusive access might proceed under some circumstances.
- Non-overlapping parts of interlocking records might be updated by different users.
- Timeouts could occur, causing locks and/or requests to be cancelled.
Most multiuser database systems at the time were hardwired and LAN based, so Internet and cloud issues weren’t part of the picture. (This was before widespread Internet use, browsers, or the World Wide Web.) Frontend programs were built out of compiled or interpreted programs written in proprietary languages. The use of LANs meant that interrupt events came directly through hardware drivers and were not processed by higher-level system services.
Prior to the test automation project, the straightforward locking sequences were tested using manual scripts on two terminals. For example,
- One user would open a record for nonexclusive update (which should lock the record from being modified but allow reading of the record by other users).
- A second user would open and attempt to modify the record (thus successfully opening but then encountering a record lock).
- Another test would have the first user opening for nonexclusive read (which should not lock the record and should allow reading and modifying of the record by other users).
- The second user would read and update the record (which should work).
The regression tests confirmed the basic functioning of the lock/unlock mechanisms. Only a subset of condition pairs could be manually tested this way because of the amount of time it took, and complex sequences of interactions were out of the question. Figure 29.2 shows an example of the interaction of two users attempting to access the same record.
Figure 29.2 Record locking example
In relational databases, updating a record can write data in many tables and cause updates to multiple indexes. Different users running different programs may reference some common data fields along with unique data. The data records are contained in multiple files (called tables), and programs reference some subset of the fields of data across the database. Intermittent, seemingly unreproducible problems could occur when the requests overlapped at precisely the wrong times. For example, the second read request might come in while the first was in the process of updating the database record. There might be tiny windows of time during which a lock might be missed or a partially updated record returned. These kinds of combinations are extremely difficult to encounter and nearly impossible to reproduce manually. We decided that the best way to look for errors was to generate lots of database activities from multiple users at the same time.
The challenge was to create multithreaded tests that could find timing-related problems of this type. The goal was to produce tests that would generate lots of conditions and could detect the bugs and provide enough failure information to the developers so they could isolate the cause and have some chance at fixing the bugs.
Automated tests: We created a single program that accessed a database using various randomly selected access methods and locking options. The test verified and logged each action. We then ran multiple instances of the program at the same time (each being its own thread or on its own machine). This generated huge numbers of combinations and sequences of database activities. The logs provided enough information to recreate the (apparent) sequence of database actions from all the threads. If no problems were detected, we discarded the logs because they could get quite large. While the tests were running, a monitoring program observed the database and log files to ensure that none of the threads reported an error or became hung.
Oracle: Watching for error returns and observing whether any of the threads terminated or took excessively long. The test program did very trivial verification of its own activities. By the nature of multiple users updating overlapping data all the time, data changes might be made by any user at any time. We couldn’t reliably confirm what was expected because some other user activity might change some data by the time the test program reread it. Because most database activities completed in fractions of seconds, if there was no lockout, the monitor program checked for multisecond delays on nonlocked transactions or after locks had been logged as released.
Method summary:
- Created a program that independently, randomly accessed records for update, read, insert, and delete. Different types of record locking were randomly included with the requests. Each program logged its activity for diagnostic purposes and checked for reasonable responses to its requests.
- Ran multiple instances of the program at the same time so they potentially accessed the same data and could interfere with one another. Access should have been denied if records were locked by other processes and allowed if none of the other threads was locking the referenced record.
- Created and ran another program to monitor the log file and the database engine to detect problem indications and shut down if a problem occurred.
Because the threads were running doing random activities, different combinations and sequences of activities were generated at a high rate of speed. The programs might have detected errors, or the threads might hang or abnormally terminate, indicating the presence of bugs. Each instance of the test generated large numbers of combinations of events and different timing sequences. The number of actions was limited by the amount of time we allocated for the lock testing. We sometimes ran the test for a few minutes, but at other times it could run an hour or longer. Each thread might only do hundreds of database actions per second because of the time it took for waiting, error checking, and logging. We ran from three to a dozen threads using multiple networked systems, so a minute of testing might generate 100,000 to 300,000 possible locking conditions.
Results: We caught and were able to fix a number of interesting combinations, timing-related bugs, and one design problem. For example, a bug might come up when:
- User A opens a record for update.
- User B waits for the record to be unlocked to do its own update.
- User C waits for the record to be unlocked to do its own update.
- User A modifies the data but releases the lock without committing the change.
- User B modifies the data but releases the lock without committing the change.
- User C updates the data, commits it, and releases the lock.
- User C’s data was not written into the database.
I was surprised because a few of the timing- and sequence-related bugs were not related to the record locking itself. If the commits occurred at the same time (within a tiny time window), the database could become corrupted by simultaneous writes of different records by multiple users in a single table. Although the records were not locked because the users were referencing different rows, the data could become switched.
We couldn’t be certain that we caught all the bugs because of the nature of these kinds of timing- and sequence-related problems. Although millions of combinations were tried and checked, there were myriad possibilities for errors that we couldn’t detect or didn’t check for. Trillions of combinations wouldn’t amount to a measurable percentage of the total number of possibilities. But, to the best of my knowledge, there were no reported field problems of that nature for at least a year after we created these tests. (I moved on and no longer had access to such information.)
We didn’t leave reproducibility to chance, although even running the same series of inputs doesn’t always reproduce a problem. The at-random tests used pseudorandom numbers; that is, we recorded seed values to be able to restart the same random sequences. This approach substantially improves reproducibility. We generated a new seed first when we wanted to do a new random walk, and we reused the seed to rerun a test.
The archiving system is critical for tracing back to find the likely cause and also as the test oracle. Much of the data being recorded can be checked for consistency and obvious outliers to detect when likely bugs are encountered. I tend to log the things developers tell me might be important to them as the test progresses and then “dump the world” when a bug is suspected.
We used some functional test suites that were available for SQL, including from the National Bureau of Standards (which later became the National Institute of Standards and Technology), but they only checked basic functionality. We used them to some degree, but they were not random, asynchronous, or multithreaded. TPC-B wasn’t created until several years later.
Recognizing the root cause of reported bugs required serious investigation because the failures we were seeking generally required multiple simultaneous (or a specific sequence of) events. Many of the factors we looked at were environmental. We were primarily looking for fundamental violations of the locking rules (deadlocks and data corruption), so recognizing those failures was straightforward. Identifying the cause was more difficult and frustrating. It sometimes took a lot of investigation, and once in a while, we gave up looking for the cause. This was frustrating because we knew there was a bug, but we couldn’t do anything about it other than look for other symptoms. Most of the time, though, the developers were able to identify the probable cause by looking for the possible ways the failure could have happened.