Discussed this with @corvus_ch already, that function can possibly return the same mail address when called multiple times.

After I thought more about this, it occured to me that this is actually the reason for one of the test hickups, see #1404618: Investigate test hickups. We generate 100 mails there, so that chance for a duplicate is quite high. The result is that we only subscribe 99 different subscribers, leading to only 99 mails and the test fails.

Fix is simple:

Add a static $mails variable, a do/while loop to generate one until we have on that does not exist yet in $mails and then add it and return it.

Comments

berdir’s picture

Title: SimplenewsTestCase::randomMail() should ensure uniqueness of mail address. » SimplenewsTestCase::randomMail() should ensure uniqueness of mail address
Assigned: Unassigned » corvus_ch
corvus_ch’s picture

berdir’s picture

Status: Active » Needs work

Thanks!

+++ b/tests/simplenews.testundefined
@@ -56,12 +59,20 @@ class SimplenewsTestCase extends DrupalWebTestCase {
+   * The generated addresses are stored in a class variable. Each generated
+   * adress ischecked against this store to prevent duplicates.

missing space between ischecked.

+++ b/tests/simplenews.testundefined
@@ -56,12 +59,20 @@ class SimplenewsTestCase extends DrupalWebTestCase {
   function randomEmail($number = 4, $prefix = 'simpletest_', $domain = 'example.com') {
-    return strtolower($this->randomName($number, $prefix) . '@' . $domain);
+    $result = '';
+    do {
+      $result = strtolower($this->randomName($number, $prefix) . '@' . $domain);
+    } while (in_array($result, $this->mailadress_cache));
+    $this->mailadress_cache[] = $result;

Maybe use $mail instead of the generic $result for the variable?

Remember to set the issue status to needs review when uploading a patch.

corvus_ch’s picture

Status: Needs work » Needs review
StatusFileSize
new1.59 KB
berdir’s picture

Status: Needs review » Fixed

Thanks, commited.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.