Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent results with many instances #272

Closed
ROTGP opened this issue Jan 22, 2021 · 3 comments
Closed

Inconsistent results with many instances #272

ROTGP opened this issue Jan 22, 2021 · 3 comments

Comments

@ROTGP
Copy link

ROTGP commented Jan 22, 2021

Summary

I have been using faker within Orchestral Testbench. My code generates many instances of faker (one for each of my tests), and each instance is seeded deterministically and generates a large number of variables. My tests started failing, especially when changing between versions of php (7.3, 8.0.1). In summary, I expect faker to behave deterministically - but it doesn't. I've included example code below. On my system, it consistently fails on iteration #5961. I'm not sure if this is a memory issue? I ended up solving it by creating a static instance of faker, and reseeding it. However, I thought I'd create this issue in case anyone else has run into this.

Versions

fakerphp/faker v1.13.0 / php 8.0.1

Self-enclosed code snippet for reproduction

$expected = '234,299,984,500,634,563,254,832,504,421,778,973,198,709,235,740,836,263,88,848,320,319,41,186,3,336,490,891,813,798,384,30,274,118,292,728,918,541,283,872,543,414,856,779,373,422,674,814,442,826,434,105,618,283,513,65,651,941,403,240,806,11,522,384,86,332,319,445,90,670,697,593,890,76,829,853,46,556,626,882,548,272,184,864,799,229,147,165,643,310,248,598,296,132,884,984,679,467,165,876,605,296,93,872,174,161,845,659,384,402,945,436,988,647,540,409,179,149,746,171,597,606,99,366,462,372,412,2,39,449,357,127,79,918,305,761,665,337,774,215,956,803,576,612,680,778,361,114,346,421,43,232,880,441,764,471,878,351,417,706,397,821,492,863,598,392,262,283,702,506,25,967,303,670,242,995,438,331,566,617,475,748,705,865,934,616,15,867,340,957,501,508,18,106,556,663,318,169,483,465,416,92,854,855,68,659,533,397,782,884,719,544,586,721,37,866,351,856,563,894,696,491,491,977,324,402,159,790,50,803,660,844,108,943,826,499,886,248,637,327,218,2,753,708,898,987,250,238,527,734,405,963,857,816,819,309,358,210,48,477,755,52,454,696,227,97,622,648,72,345,72,65,567,220,534,137,990,250,18,650,573,428,792,835,443,966,878,817,584,193,709,808,148,373,575,744,309,186,104,414,440,773,829,351,498,765,819,835,90,785,800,34,431,261,589,139,198,127,567,371,709,322,37,934,974,559,552,673,745,77,438,250,385,355,168,983,839,70,405,794,783,577,154,581,603,234,224,483,616,448,21,131,751,32,827,843,547,980,491,980,484,799,845,96,822,217,14,686,849,676,252,586,457,574,579,0,116,255,339,751,94,612,288,373,77,843,206,238,574,165,710,248,656,596,199,927,351,581,93,96,814,109,213,710,393,574,140,295,384,178,747,74,167,278,737,448,508,385,353,361,782,445,896,960,38,247,317,465,136,883,310,816,973,648,946,690,184,279,69,728,748,652,914,354,458,263,130,543,194,746,403,306,973,906,147,175,274,592,709,409,647,466,210,608,151,434,466,79,559,8,122,366,378,308,576,595,485,966,105,953,697,794,396,267,794,20,590,411,185,541,162,280,434,111,945,155,989,457,229,25';

for ($i = 0; $i < 10000; $i++) {
     $faker = Faker::create();
     $faker->seed(10);
     $result = [];
            
     for ($j = 0; $j < 500; $j++)
          $result[] = $faker->numberBetween(0, 1000);

     $result = implode(',', $result);
     if ($expected != $result) die('FAIL: ' . $i);
}
@pimjansen
Copy link

pimjansen commented Jan 24, 2021

Running this on different versions indeed gives different result. However i see PHP 7.3/7.4/8.0/latest all behave the same way. The way the example is executed though is not really a best practice where we create thousands of Faker instances.

php8.0       | FAIL: 398
phplatest    | FAIL: 398
php8.0 exited with code 0
php7.4       | FAIL: 398
php7.3       | FAIL: 398
phplatest exited with code 0
php7.4 exited with code 0
php7.3 exited with code 0
php7.2       | FAIL: 3597
php7.2 exited with code 0
php7.1       | FAIL: 3197
php7.1 exited with code 0

@pimjansen
Copy link

@ROTGP what i can suggest is to create a single Faker instance in these ways and reseed the instance itself.

@ROTGP
Copy link
Author

ROTGP commented Jan 24, 2021

@pimjansen yup, using a static instance and reseeding it is what I ended up doing. I understand that it's somewhat of an extreme edge-case. Feel free to close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants