{"action":"created","issue":{"url":"https://api.github.com/repos/nodejs/node/issues/3697","labels_url":"https://api.github.com/repos/nodejs/node/issues/3697/labels{/name}","comments_url":"https://api.github.com/repos/nodejs/node/issues/3697/comments","events_url":"https://api.github.com/repos/nodejs/node/issues/3697/events","html_url":"https://github.com/nodejs/node/pull/3697","id":115571494,"number":3697,"title":"test: reduce memory use in test stringbytes","user":{"login":"thinkingdust","id":7787256,"avatar_url":"https://avatars.githubusercontent.com/u/7787256?v=3","gravatar_id":"","url":"https://api.github.com/users/thinkingdust","html_url":"https://github.com/thinkingdust","followers_url":"https://api.github.com/users/thinkingdust/followers","following_url":"https://api.github.com/users/thinkingdust/following{/other_user}","gists_url":"https://api.github.com/users/thinkingdust/gists{/gist_id}","starred_url":"https://api.github.com/users/thinkingdust/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thinkingdust/subscriptions","organizations_url":"https://api.github.com/users/thinkingdust/orgs","repos_url":"https://api.github.com/users/thinkingdust/repos","events_url":"https://api.github.com/users/thinkingdust/events{/privacy}","received_events_url":"https://api.github.com/users/thinkingdust/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/nodejs/node/labels/buffer","name":"buffer","color":"f7c6c7"},{"url":"https://api.github.com/repos/nodejs/node/labels/lts-watch-v4.x","name":"lts-watch-v4.x","color":"eb6420"},{"url":"https://api.github.com/repos/nodejs/node/labels/memory","name":"memory","color":"eb6420"},{"url":"https://api.github.com/repos/nodejs/node/labels/test","name":"test","color":"990099"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":22,"created_at":"2015-11-06T19:29:54Z","updated_at":"2015-11-20T16:39:48Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/nodejs/node/pulls/3697","html_url":"https://github.com/nodejs/node/pull/3697","diff_url":"https://github.com/nodejs/node/pull/3697.diff","patch_url":"https://github.com/nodejs/node/pull/3697.patch"},"body":"When I run the string bytes tests dealing with strings of length kStringMaxLength or more on a Windows test machine with 4GB memory I see the tests skipped or failed with the following outputs respectively.\r\n* `1..0 # Skipped: intensive toString tests due to memory confinements`\r\n* `RangeError: Invalid array buffer length`\r\n\r\nThe code being used to determine if the test should be skipped is:\r\n```\r\n try {\r\n  new Buffer(kStringMaxLength * 3);\r\n } catch(e) {\r\n  assert.equal(e.message, 'Invalid array buffer length');\r\n  console.log(\r\n       '1..0 # Skipped: intensive toString tests due to memory confinements');\r\n   return;\r\n }\r\n```\r\n\r\nA problem with this approach is that the garbage collector does not necessarily run between the tried allocation and the necessary allocations later. That means that even though no exception is thrown in the try block since the machine has enough memory, the later allocations fail since the memory is now taken.\r\n\r\nTo verify this, I ran the test with `Release\\node.exe --expose-gc test\\parallel\\test-stringbytes-external-at-max.js` to expose `global.gc()` which I used after the try catch block. With this setup the test would either skip or succeed as desired.\r\n\r\nTo solve the issue, I removed the Buffer allocations that were used to check if the tests should be skipped and moved the actual Buffer allocations into the try block so the test can still be skipped if memory allocation fails here. The tests should now use less total memory and be less likely to be skipped and more importantly, less likely to fail due to a memory constraint when they are not skipped.\r\n"},"comment":{"url":"https://api.github.com/repos/nodejs/node/issues/comments/158453900","html_url":"https://github.com/nodejs/node/pull/3697#issuecomment-158453900","issue_url":"https://api.github.com/repos/nodejs/node/issues/3697","id":158453900,"user":{"login":"mhdawson","id":9373002,"avatar_url":"https://avatars.githubusercontent.com/u/9373002?v=3","gravatar_id":"","url":"https://api.github.com/users/mhdawson","html_url":"https://github.com/mhdawson","followers_url":"https://api.github.com/users/mhdawson/followers","following_url":"https://api.github.com/users/mhdawson/following{/other_user}","gists_url":"https://api.github.com/users/mhdawson/gists{/gist_id}","starred_url":"https://api.github.com/users/mhdawson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhdawson/subscriptions","organizations_url":"https://api.github.com/users/mhdawson/orgs","repos_url":"https://api.github.com/users/mhdawson/repos","events_url":"https://api.github.com/users/mhdawson/events{/privacy}","received_events_url":"https://api.github.com/users/mhdawson/received_events","type":"User","site_admin":false},"created_at":"2015-11-20T16:39:48Z","updated_at":"2015-11-20T16:39:48Z","body":"Another failure on ARM today: https://ci.nodejs.org/job/node-test-binary-arm/81/RUN_SUBSET=4,nodes=pi2-raspbian-wheezy/console\r\n\r\nWould be nice to get the fix in."}}