Incomplete tests for lock_* API routines and assorted bugs

Created on 23 May 2010, almost 15 years ago
Updated 19 July 2023, almost 2 years ago

This applies to the tests in file lock.test which I'm assuming represents the sum total of tests for the code in lock.inc

(1) Untested functions. The following - 6 out of 7 functions - do not have explicit tests.

lock_initialize
lock_may_be_available
lock_release - this function is used but not tested
lock_release_all - tested indirectly
lock_wait
_lock_id - tested indirectly

(2) The tests for lock_aquire only validate the return status rather that validating the expected side-effects resulting from the call. There are two problems with this; first there are two paths resulting in a success status and the tests does not explicitly distinguish between them, secondly the behaviour of the API depends on the side-effects associated with the call.

The following basic tests are suggested (based on the code rather than the requirements or design which is far from ideal). I've indicated where I think some implementation bugs exist:


Pre-conditions: global array $locks is not defined
Post-conditions: global array $locks is defined and is empty

- Two sets of basic tests
(1a) Pre-conditions: lock is not defined in $locks, row does not exists in table semaphore
Post-conditions if result is TRUE: lock is defined in $locks, row exists in table semaphore with value equal to _lock_id, expiry greater than or equal to time of call plus default expiry increment.
Post condition if result false: Lock is not defined in $locks, row does not exist in table semaphore
(1b) Explicit value for timeout.
Pre-conditions: lock is not defined in $locks, row does not exists in table semaphore
Post-conditions if result is TRUE: lock is defined in $locks, row exists in table semaphore with value equal to _lock_id, expiry greater than or equal to time of call plus passed expiry increment.
Post condition if result false: Lock is not defined in $locks, row does not exist in table semaphore
(2a) Pre-conditions: lock is defined in $locks, row exists in table semaphore
Post-conditions if result is TRUE: lock is defined in $locks, row exists in table semaphore with value equal to _lock_id, expiry greater than or equal to time of call plus default expiry increment.
Post condition if result false: Lock is not defined in $locks, row does not exist in table semaphore
(2b) Explicit value for timeout.
Pre-conditions: lock is defined in $locks, row exists in table semaphore
Post-conditions if result is TRUE: lock is defined in $locks, row exists in table semaphore with value equal to _lock_id, expiry greater than or equal to time of call plus passed expiry increment.
Post condition if result false: Lock is not defined in $locks, row does not exist in table semaphore



(1) Lock name not in semaphore table
Preconditions: row for lock not in semaphore state of entry in $locks undefined
Postconditions: Return is TRUE, row for lock not in semaphore table [? the value in $locks should be unset]
(2) Lock name in semaphore table
(2a) Preconditions: Row in semaphore table and lock NOT expired
Postconditions: Return should be FALSE [bug? value in $locks should be set if it is not because a valid lock exists]
(2b) Preconditions: Row in semaphore table and lock expired
Postconditions: Return TRUE, row not in semaphore table, [? the value in $locks should be unset]
(2c) Tricky without intervention in form of extra code or manual breakpoints.
Preconditions: Row in semaphore table and lock expired
Mid-condition: After initial db_query additional row inserted that is not expired
Postconditions: Return FALSE, row exists in semaphore table [? value in $locks should be set if it is not because a valid lock exists]



(1) Precondition: Row does not exist in semaphore table
Postcondition: Return TRUE, $locks is unset
(2a) Preconditions: Row exists with value equal current internal _lock_id, $locks is undefined
Postconditions: Row does not exists in semaphore, $locks is unset
(2b) Preconditions: Row exists with value not equal to current internal _lock_id, $locks is undefined
Postconditions: Return FALSE, row still exists unchanged, $locks is set.



(1) Preconditions: One or more rows in semaphore exists with a value equal to _lock_id and function called with no arguments
Postconditions: (Should return TRUE] No rows exist in semaphore with currenty value equal to _lock_id
(2) Preconditions: One or more rows in semaphore exists with a value equal to value passed as argument
Postconditions:No rows in semaphore exists with a value equal to value passed as argument
Postconditions: (Should return FALSE] Semaphore table is unchanged



Observations: The side effects generated by lock_may_be_available are not considered in these proposed tests
(1) Preconditions: Lock name not in semaphore table
Postconditions: Return FALSE
(2) Preconditions: Lock name in semaphore table, lock is expired.
Postconditions: Return FALSE.
(3) Preconditions: Lock name in semaphore table, lock expires at least 2*delay.
Postconditions: Return TRUE.


Don't know enough to about things like drupal_register_shutdown_function yet :-( Would need to verify that saved lock_id is being retrieved and that the shutdown function only registered once.

πŸ“Œ Task
Status

Postponed: needs info

Version

9.5

Component
BaseΒ  β†’

Last updated about 4 hours ago

Created by

πŸ‡¦πŸ‡ΊAustralia lostchord

Live updates comments and jobs are added and updated live.
  • Needs backport to D7

    After being applied to the 8.x branch, it should be considered for backport to the 7.x branch. Note: This tag should generally remain even after the backport has been written, approved, and committed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Think a number of these have been deprecated. So wonder if still a valid task?

    If so will need an issue summary update.

    Thanks!

  • Status changed to Closed: outdated 8 days ago
  • πŸ‡³πŸ‡ΏNew Zealand quietone

    There are tests of the lock system, so perhaps this is outdated. The lack of response to #23 suggest that this is outdated/ So, I am closing this.

    If tests need to be added, open a new issue.

Production build 0.71.5 2024