WordPress.org

Make WordPress Core

Opened 10 months ago

Last modified 5 months ago

#37371 accepted enhancement

Reduce reliance on randomness in tests

Reported by: johnbillion Owned by: johnbillion
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords: needs-patch
Focuses: Cc:

Description

39 of core's tests rely on rand_str() returning a different value each time it's called in order to pass. It's entirely possible that rand_str() could return an identical value twice, and therefore the test would randomly (ho ho) fail.

Let's remove all the unnecessary uses of rand_str(), where a fixed string would suffice. This will also shave off some milliseconds.

Attachments (1)

37371.patch (17.4 KB) - added by johnbillion 10 months ago.

Download all attachments as: .zip

Change History (11)

@johnbillion
10 months ago

#1 @johnbillion
10 months ago

  • Keywords has-patch added; needs-patch removed

37371.patch replaces all instances of rand_str() with static strings where the test will fail if rand_str() were to return sequential identical strings.

#2 @johnbillion
8 months ago

  • Milestone changed from Future Release to 4.7

#3 @johnbillion
8 months ago

In 38382:

Build/Test Tools: Remove many unnecessary calls to rand_str() which can, in theory, fail at random. Static strings are much more appropriate.

See #37371

#4 @jorbin
7 months ago

@johnbillion Do you want to remove the rest of the calls to rand_strl? If so, good first bug?

#5 @johnbillion
7 months ago

  • Keywords needs-patch good-first-bug added; has-patch removed
  • Milestone changed from 4.7 to Future Release

#6 @johnbillion
7 months ago

  • Keywords good-first-bug removed
  • Owner set to johnbillion
  • Status changed from new to accepted
  • Summary changed from Reduce reliance on rand_str() in tests to Reduce reliance on randomness in tests

There's also a bunch of instances of rand() in tests which are just as unnecessary.

#7 @johnbillion
7 months ago

In 38762:

Build/Test Tools: Begin eliminating unnecessary randomness in tests.

Although unlikely, clashes in randomly generated strings could cause unexpected failures. In addition, most randomness is entirely unnecessary, is bad practice, and increases test time (however small it may be).

See #37371

#8 @johnbillion
7 months ago

In 38763:

Build/Test Tools: Continue eliminating randomness in tests.

See [38762]
See #37371

#9 @johnbillion
6 months ago

In 38938:

Build/Test Tools: Continue eliminating randomness in tests.

See #37371

#10 @johnbillion
5 months ago

In 39556:

Build/Test Tools: Remove some more randomness.

See #37371

Note: See TracTickets for help on using tickets.