Skip to content

[Status] Organize metrics stuff into metrics_collector, tests into __test__ directories, remove mock-fs for the cgroup test#17788

Merged
tsullivan merged 8 commits intoelastic:masterfrom
tsullivan:status/isolate-metrics-class-remove-mockfs
Apr 25, 2018
Merged

[Status] Organize metrics stuff into metrics_collector, tests into __test__ directories, remove mock-fs for the cgroup test#17788
tsullivan merged 8 commits intoelastic:masterfrom
tsullivan:status/isolate-metrics-class-remove-mockfs

Conversation

@tsullivan
Copy link
Copy Markdown
Member

This is a standalone PR to make #17773 more of an atomic PR.

Replacing mock-fs with a custom inline Jest mock is necessary because the next PR will mock os, and that was causing conflicts with mock-fs.

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

readCPUAcctUsage(cpuAcctPath).catch(rejectUnlessFileNotFound),
readCPUFsPeriod(cpuPath).catch(rejectUnlessFileNotFound),
readCPUFsQuota(cpuPath).catch(rejectUnlessFileNotFound),
readCPUStat(cpuPath).catch(rejectUnlessFileNotFound)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tylersmalley I could use advice here - can we chat about this?

Without these changes, I was getting unhandled rejection warnings. They weren't causing the tests to fail, but they were pretty messy. Not sure what I've changed that makes the warnings quiet down after putting the catches up here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just went ahead and undid this because I don't want to hack the code to get it to not complain about my mock module.

I still would really like to understand why the unhandled rejections are happening. This code is exactly like https://runkit.com/miu/5ad8d36c36503a0012574310

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@tsullivan
Copy link
Copy Markdown
Member Author

Currently there are unhandled exception thrown in fileContentsToInteger that for some unknown reason are not handled when readFile is a mocked function.

Appreciate any advice here, or LMK if this can be ignored.

% node scripts/jest.js src/server/status
 PASS  src/server/status/metrics_collector/__test__/metrics.test.js
 PASS  src/server/status/metrics_collector/__test__/metrics_collector.test.js
 PASS  src/server/status/__test__/status.test.js
Unhandled rejection Error: Stub File Sytem Stub Error: /sys/fs/cgroup/cpuacct/sfizln/cpuacct.usage
Unhandled rejection Error: Stub File Sytem Stub Error: /sys/fs/cgroup/cpu/sfizln/cpu.cfs_period_us
Unhandled rejection Error: Stub File Sytem Stub Error: /sys/fs/cgroup/cpu/sfizln/cpu.cfs_quota_us
 PASS  src/server/status/metrics_collector/__test__/cgroup.test.js
 PASS  src/server/status/__test__/server_status.test.js
 PASS  src/server/status/metrics_collector/__test__/sum_accumulate.test.js
 PASS  src/server/status/__test__/wrap_auth_config.test.js

Test Suites: 7 passed, 7 total
Tests:       51 passed, 51 total
Snapshots:   5 passed, 5 total
Time:        1.945s
Ran all test suites matching /src\/server\/status/i.

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@tsullivan
Copy link
Copy Markdown
Member Author

18:30:23        ?- ? fail: "discover app discover app field data doc view should show oldest time first"
18:30:23        ?        Error: expected 'September 22nd 2015, 23:50:13.253\ntype:apache index:logstash-2015.09.22 @timestamp:September 22nd 2015, 23:50:13.253 ip:238.171.34.42 extension:jpg response:200 geo.coordinates:{ "lat": 38.66494528, "lon": -88.45299556 } geo.src:FR geo.dest:KH geo.srcdest:FR:KH @tags:success, info utc_time:September 22nd 2015, 23:50:13.253 referer:http://twitter.com/success/nancy-currie agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322) clientip:238.171.34.42 bytes:7,124 host:media-for-the-masses.theacademyofperformingartsandscience.org request:/uploads/karl-henize.jpg url:https://media-for-the-masses.theacademyofperformingartsandscience.org/uploads/karl-henize.jpg @message:238.171.34.42 - - [2015-09-22T23:50:13.253Z] "GET /uploads/karl-henize.jpg HTTP/1.1" 200 7124 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)" spaces:this is a thing with lots of spaces wwwwoooooo xss:<script>console.log("xss")</script> headings:<h3>alexander-viktorenko</h5>, http://nytimes.com/warning/michael-massimino links:@www.slate.com, http://www.slate.com/security/frederick-w-leslie, www.www.slate.com relatedContent:{ "url": "http://www.laweekly.com/music/bjork-at-the-nokia-theatre-12-12-2408191", "og:type": "article", "og:title": "Bjork at the Nokia Theatre, 12/12", "og:description": "Bjork at the Nokia Theater, December 12 By Randall Roberts Last night&rsquo;s Bjork show at the Dystopia &ndash; er, I mean Nokia -- Theatre downtown di...", "og:url": "http://www.laweekly.com/music/bjork-at-the-nokia-theatre-12-12-2408191", "article:published_time": "2007-12-13T12:19:35-08:00", "article:modified_time": "2014-11-27T08:28:42-08:00", "article:section": "Music", "og:image": "http://IMAGES1.laweekly.com/imager/bjork-at-the-nokia-theatre-12-12/u/original/2470701/bjorktn003.jpg", "og:image:height": "334", "og:image:width": "480", "og:site_name": "LA Weekly", "twitter:title": "Bjork at the Nokia Theatre, 12/12", "twitter:description": "Bjork at the Nokia Theater, December 12 By Randall Roberts Last night&rsquo;s Bjork show at the Dystopia &ndash; er, I mean Nokia -- Theatre downtown di...", "twitter:card": "summary", "twitter:image": "http://IMAGES1.laweekly.com/imager/bjork-at-the-nokia-theatre-12-12/u/original/2470701/bjorktn003.jpg", "twitter:site": "@laweekly" }, { "url": "http://www.laweekly.com/music/the-rapture-at-the-mayan-7-25-2401011", "og:type": "article", "og:title": "The Rapture at the Mayan, 7/25", "og:description": "If you haven&rsquo;t yet experienced the phenomenon of people walk-dancing, apparently the best place to witness this is at a Rapture show. Here&rsquo;s...", "og:url": "http://www.laweekly.com/music/the-rapture-at-the-mayan-7-25-2401011", "article:published_time": "2007-07-26T12:42:30-07:00", "article:modified_time": "2014-11-27T08:00:51-08:00", "article:section": "Music", "og:image": "http://IMAGES1.laweekly.com/imager/the-rapture-at-the-mayan-7-25/u/original/2463272/rapturetn05.jpg", "og:image:height": "321", "og:image:width": "480", "og:site_name": "LA Weekly", "twitter:title": "The Rapture at the Mayan, 7/25", "twitter:description": "If you haven&rsquo;t yet experienced the phenomenon of people walk-dancing, apparently the best place to witness this is at a Rapture show. Here&rsquo;s...", "twitter:card": "summary", "twitter:image": "http://IMAGES1.laweekly.com/imager/the-rapture-at-the-mayan-7-25/u/original/2463272/rapturetn05.jpg", "twitter:site": "@laweekly" } machine.os:win 7 machine.ram:7,516,192,768 _id:AU_x3_g4GFA8no6QjkYX _type:doc _index:logstash-2015.09.22 _score: - relatedContent.article:modified_time:November 26th 2014, 03:39:26.000, November 26th 2014, 04:36:10.000 relatedContent.article:published_time:October 17th 2005, 07:10:18.000, October 17th 2005, 07:10:18.000' to equal 'September 22nd 2015, 23:50:13.253\ntype:apache index:logstash-2015.09.22 @timestamp:September 22nd 2015, 23:50:13.253 ip:238.171.34.42 extension:jpg response:200 geo.coordinates:{ "lat": 38.66494528, "lon": -88.45299556 } geo.src:FR geo.dest:KH geo.srcdest:FR:KH @tags:success, info utc_time:September 22nd 2015, 23:50:13.253 referer:http://twitter.com/success/nancy-currie agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322) clientip:238.171.34.42 bytes:7,124 host:media-for-the-masses.theacademyofperformingartsandscience.org request:/uploads/karl-henize.jpg url:https://media-for-the-masses.theacademyofperformingartsandscience.org/uploads/karl-henize.jpg @message:238.171.34.42 - - [2015-09-22T23:50:13.253Z] "GET /uploads/karl-henize.jpg HTTP/1.1" 200 7124 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)" spaces:this is a thing with lots of spaces wwwwoooooo xss:<script>console.log("xss")</script> headings:<h3>alexander-viktorenko</h5>, http://nytimes.com/warning/michael-massimino links:@www.slate.com, http://www.slate.com/security/frederick-w-leslie, www.www.slate.com relatedContent:{ "url": "http://www.laweekly.com/music/bjork-at-the-nokia-theatre-12-12-2408191", "og:type": "article", "og:title": "Bjork at the Nokia Theatre, 12/12", "og:description": "Bjork at the Nokia Theater, December 12 By Randall Roberts Last night&rsquo;s Bjork show at the Dystopia &ndash; er, I mean Nokia -- Theatre downtown di...", "og:url": "http://www.laweekly.com/music/bjork-at-the-nokia-theatre-12-12-2408191", "article:published_time": "2007-12-13T12:19:35-08:00", "article:modified_time": "2014-11-27T08:28:42-08:00", "article:section": "Music", "og:image": "http://IMAGES1.laweekly.com/imager/bjork-at-the-nokia-theatre-12-12/u/original/2470701/bjorktn003.jpg", "og:image:height": "334", "og:image:width": "480", "og:site_name": "LA Weekly", "twitter:title": "Bjork at the Nokia Theatre, 12/12", "twitter:description": "Bjork at the Nokia Theater, December 12 By Randall Roberts Last night&rsquo;s Bjork show at the Dystopia &ndash; er, I mean Nokia -- Theatre downtown di...", "twitter:card": "summary", "twitter:image": "http://IMAGES1.laweekly.com/imager/bjork-at-the-nokia-theatre-12-12/u/original/2470701/bjorktn003.jpg", "twitter:site": "@laweekly" }, { "url": "http://www.laweekly.com/music/the-rapture-at-the-mayan-7-25-2401011", "og:type": "article", "og:title": "The Rapture at the Mayan, 7/25", "og:description": "If you haven&rsquo;t yet experienced the phenomenon of people walk-dancing, apparently the best place to witness this is at a Rapture show. Here&rsquo;s...", "og:url": "http://www.laweekly.com/music/the-rapture-at-the-mayan-7-25-2401011", "article:published_time": "2007-07-26T12:42:30-07:00", "article:modified_time": "2014-11-27T08:00:51-08:00", "article:section": "Music", "og:image": "http://IMAGES1.laweekly.com/imager/the-rapture-at-the-mayan-7-25/u/original/2463272/rapturetn05.jpg", "og:image:height": "321", "og:image:width": "480", "og:site_name": "LA Weekly", "twitter:title": "The Rapture at the Mayan, 7/25", "twitter:description": "If you haven&rsquo;t yet experienced the phenomenon of people walk-dancing, apparently the best place to witness this is at a Rapture show. Here&rsquo;s...", "twitter:card": "summary", "twitter:image": "http://IMAGES1.laweekly.com/imager/the-rapture-at-the-mayan-7-25/u/original/2463272/rapturetn05.jpg", "twitter:site": "@laweekly" } machine.os:win 7 machine.ram:7,516,192,768 _id:AU_x3_g4GFA8no6QjkYX _type:doc _index:logstash-2015.09.22 _score: - relatedContent.article:modified_time:November 27th 2014, 16:00:51.000, November 27th 2014, 16:28:42.000 relatedContent.article:published_time:July 26th 2007, 19:42:30.000, December 13th 2007, 20:19:35.000'
18:30:23        ?         at Assertion.assert (node_modules/expect.js/index.js:96:13)
18:30:23        ?         at Assertion.be.Assertion.equal (node_modules/expect.js/index.js:216:10)
18:30:23        ?         at Assertion.(anonymous function) [as be] (node_modules/expect.js/index.js:69:24)
18:30:23        ?         at Command.<anonymous> (test/functional/apps/discover/_field_data.js:75:47)
18:30:23        ?         at runCallback (node_modules/leadfoot/Command.js:526:31)
18:30:23        ?         at Command.<anonymous> (node_modules/leadfoot/Command.js:543:11)
18:30:23        ?         at node_modules/dojo/Promise.js:156:41
18:30:23        ?         at run (node_modules/dojo/Promise.js:51:33)
18:30:23        ?         at node_modules/dojo/nextTick.js:35:17
18:30:23        ?         at _combinedTickCallback (internal/process/next_tick.js:131:7)
18:30:23        ?         at process._tickDomainCallback (internal/process/next_tick.js:218:9)
18:30:23        ?         
18:30:23        ?         at Command.then (node_modules/leadfoot/Command.js:542:10)
18:30:23        ?         at Context.<anonymous> (test/functional/apps/discover/_field_data.js:73:57)
18:30:23        ?         at Object.apply (src/functional_test_runner/lib/mocha/wrap_function.js:73:30)

jenkins test this

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@tsullivan tsullivan merged commit 706f0f2 into elastic:master Apr 25, 2018
@tsullivan tsullivan deleted the status/isolate-metrics-class-remove-mockfs branch April 25, 2018 17:37
tsullivan added a commit to tsullivan/kibana that referenced this pull request Apr 25, 2018
…_test__ directories, remove mock-fs for the cgroup test (elastic#17788)

* [Status] Organize tests into __test__ directories

* custom mock for fs in cgroups test

* work around unhandled rejection errors

* simplify fserror construct

* put fs readFile mockImpl in beforeAll for pretty

* undo hacking the code to suppress unhandled promise rejections

* test files back to sibling of the module
tsullivan added a commit that referenced this pull request Apr 30, 2018
…_test__ directories, remove mock-fs for the cgroup test (#17788) (#18578)

* [Status] Organize tests into __test__ directories

* custom mock for fs in cgroups test

* work around unhandled rejection errors

* simplify fserror construct

* put fs readFile mockImpl in beforeAll for pretty

* undo hacking the code to suppress unhandled promise rejections

* test files back to sibling of the module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants