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

fix(#368): added utility function for elapsed time tracking #389

Merged
merged 20 commits into from
Dec 16, 2024

Conversation

trapvpack
Copy link
Contributor

closes #368
@yegor256 take a look please

@yegor256
Copy link
Member

@maxonfjvipon please, check this one (ignore the build problems, they are not related to this branch)

@@ -33,6 +33,10 @@ const path = require('path');
*/
module.exports = function(opts) {
const target = path.resolve(opts.target);
/**
* @todo #368
Copy link
Member

Choose a reason for hiding this comment

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

@trapvpack it's a wrong format for todo, should be:

@todo #368:30min Description of todo...
 more description with space at the beginning

src/elapsed.js Outdated

/**
* @todo #368
* Consider if this method belong is in the right place.
Copy link
Member

Choose a reason for hiding this comment

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

@trapvpack see above about todo format

src/elapsed.js Outdated
} else {
extended = `${Math.ceil(duration / 3600000)}min`;
}
let msg = `${message} in ${extended}`;
Copy link
Member

Choose a reason for hiding this comment

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

@trapvpack I think msg can be const here

src/elapsed.js Outdated
*/
module.exports.elapsed = function elapsed(task) {
const startTime = Date.now();
const tracked = {
Copy link
Member

Choose a reason for hiding this comment

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

@trapvpack let's inline this variable into task call

return task({
  print: (message) => {
    // code here
  }
})

const assert = require("assert");

describe('elapsed', function(){
const snooze = ms => new Promise(resolve => setTimeout(resolve, ms));
Copy link
Member

Choose a reason for hiding this comment

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

@trapvpack let's follow a single code style and wrap lambda arguments with braces:

const snooze = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

)
)
});

Copy link
Member

Choose a reason for hiding this comment

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

@trapvpack there's no need for space here

)
);
});

Copy link
Member

Choose a reason for hiding this comment

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

@trapvpack there's no need for space here

)
);
});

Copy link
Member

Choose a reason for hiding this comment

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

@trapvpack there's no need for space here

});

it('handles errors in task correctly', async () => {
try {
Copy link
Member

Choose a reason for hiding this comment

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

@trapvpack I think the test can be simplified with assert.throws()

});
};
};
Copy link
Member

Choose a reason for hiding this comment

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

@trapvpack this change is unnecessary

@trapvpack
Copy link
Contributor Author

@maxonfjvipon take a look, I fixed what you asked for

@yegor256
Copy link
Member

@trapvpack please, merge master branch into your branch - to make the build clean

@maxonfjvipon
Copy link
Member

maxonfjvipon commented Nov 24, 2024

@trapvpack you didn't fix all the my comments and there are some new ones from action-lint

@trapvpack
Copy link
Contributor Author

@maxonfjvipon, take a look, I think I closed all conversations. If I understood correctly, it was necessary to modify conversations without the outdated tag, correct me if this is wrong

@trapvpack
Copy link
Contributor Author

@yegor256, I merged master into my branch, but it stiil dont complete a build checks. I assume this is due to the version being raised to 0.43.0, but tag is not upped, refers to 388

@yegor256
Copy link
Member

@trapvpack all builds are clean in the master branch now

@trapvpack
Copy link
Contributor Author

@yegor256 @maxonfjvipon, take a look please

@trapvpack
Copy link
Contributor Author

@yegor256 @maxonfjvipon, take a look please😎

@@ -33,6 +33,10 @@ const path = require('path');
*/
module.exports = function(opts) {
const target = path.resolve(opts.target);
/**
* @todo #368:30min Wrap logs in 'elapsed'
* - It is necessary to use 'elapsed' in all logging cases that require output of elapsed time
Copy link
Member

Choose a reason for hiding this comment

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

@trapvpack the format is still wrong, should be:

* @todo #368:30min Wrap logs in 'elapsed'
*  It is necessary to use 'elapsed' in all logging cases that require output of elapsed time

await snooze(300);
return tracked.print('task');
}) .then(
(actual)=> assert(
Copy link
Member

Choose a reason for hiding this comment

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

@trapvpack the space after (actual) is missed

return elapsed(async (tracked) => {
await snooze(10);
return tracked.print('short task');
}) .then(
Copy link
Member

Choose a reason for hiding this comment

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

@trapvpack the space after }) is unnecessary

return elapsed(async (tracked) => {
await snooze(1200);
return tracked.print('long task');
}) .then(
Copy link
Member

Choose a reason for hiding this comment

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

@trapvpack the space after }) is unnecessary

# Conflicts:
#	src/commands/java/compile.js
#	src/elapsed.js
#	test/test_elapsed.js
@trapvpack
Copy link
Contributor Author

@maxonfjvipon, take a look please, thanks for your patience)

Copy link
Member

@maxonfjvipon maxonfjvipon left a comment

Choose a reason for hiding this comment

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

@trapvpack the last one I hope)

@trapvpack
Copy link
Contributor Author

@maxonfjvipon, take a look please, I hope I understand correctly now

Copy link
Member

@maxonfjvipon maxonfjvipon left a comment

Choose a reason for hiding this comment

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

@trapvpack let's try one more time

src/elapsed.js Outdated
* @todo #368:30min Decide if the `elapsed` utility function is in the right place,
* consider relocating it and its test file if needed
*/

Copy link
Member

Choose a reason for hiding this comment

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

@trapvpack you have two comments section here stated with /** and ended with */. The first comment is on lines 25-28, the second is on 30-44 and there's an empty line 29 between them. We don't need two comments here, it should one single comment started on line 25 and ended on line 43 or 44 with no empty lines. Also please move your todo under the function description

@trapvpack
Copy link
Contributor Author

@maxonfjvipon, take a look please, thanks for the detailed explanation

src/elapsed.js Outdated
});
};
/**
* @todo #368:30min Decide if the `elapsed` utility function is in the right place,
Copy link
Member

Choose a reason for hiding this comment

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

@trapvpack now you have 2 comments again... it should be one:


/**
 * A utility function to measure the elapsed time of a task and provide
 * detailed timing information.
 *
 * This function wraps a given task (callback function) and provides it with
 * a `tracked` object that includes a `print` method. The `print` method can
 * be used within the task to log messages along with the elapsed time
 * since the task started execution. The elapsed time is formatted in milliseconds,
 * seconds, or minutes, based on the duration.
 *
 * @param {Function} task - A callback function to be measured. The function
 *                          is invoked with a `tracked` object as an argument.
 * @return {*} Result of the wrapped callback function. The result of the
 *             `task` callback will be returned unchanged.
 * @todo #368:30min Decide if the `elapsed` utility function is in the right place,
 *  consider relocating it and its test file if needed
 */

@trapvpack
Copy link
Contributor Author

@maxonfjvipon, take a look please

Copy link
Member

@maxonfjvipon maxonfjvipon left a comment

Choose a reason for hiding this comment

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

@trapvpack now it looks good, thank you

@trapvpack
Copy link
Contributor Author

@yegor256, take a look please

@trapvpack
Copy link
Contributor Author

@yegor256, take a look please:), thanks for attention

@yegor256
Copy link
Member

@rultor merge

@rultor
Copy link
Contributor

rultor commented Nov 28, 2024

@rultor merge

@yegor256 OK, I'll try to merge now. You can check the progress of the merge here.

@rultor
Copy link
Contributor

rultor commented Nov 28, 2024

@rultor merge

@trapvpack @yegor256 Oops, I failed. You can see the full log here (spent 21min).


\u001b[0m  elapsed\u001b[0m
task in 301ms
  \u001b[32m  ✓\u001b[0m\u001b[90m measures time correctly\u001b[0m\u001b[31m (302ms)\u001b[0m
short task in 11ms
  \u001b[32m  ✓\u001b[0m\u001b[90m measures short time correctly\u001b[0m
long task in 2s
  \u001b[32m  ✓\u001b[0m\u001b[90m measures long time correctly\u001b[0m\u001b[31m (1202ms)\u001b[0m
  \u001b[32m  ✓\u001b[0m\u001b[90m handles errors in task correctly\u001b[0m

\u001b[0m  eoc\u001b[0m
  \u001b[32m  ✓\u001b[0m\u001b[90m prints its own version\u001b[0m\u001b[31m (97ms)\u001b[0m
  \u001b[32m  ✓\u001b[0m\u001b[90m prints help screen\u001b[0m\u001b[31m (108ms)\u001b[0m

\u001b[0m  eoc\u001b[0m
  \u001b[32m  ✓\u001b[0m\u001b[90m loads latest version\u001b[0m\u001b[31m (333ms)\u001b[0m

\u001b[0m  mvnw\u001b[0m
+ /home/r/repo/mvnw/mvnw --version --quiet --batch-mode --color=never --update-snapshots --fail-fast --strict-checksums
  \u001b[32m  ✓\u001b[0m\u001b[90m prints Maven own version\u001b[0m
Sources in sources
Target in target
+ /home/r/repo/mvnw/mvnw --version --quiet -Deo.version=parser -Deo.tag=homeTag --quiet -Deo.sourcesDir=/home/r/repo/sources -Deo.targetDir=/home/r/repo/target -Deo.outputDir=/home/r/repo/target/classes -Deo.generatedDir=/home/r/repo/target/generated-sources -Deo.placed=/home/r/repo/target/eo-placed.csv -Deo.placedFormat=csv --batch-mode --color=never --update-snapshots --fail-fast --strict-checksums
\u001b[0m\u001b[0m3.9.9
\u001b[0m\u001b[0m\u001b[0m\u001b[0m3.9.9
\u001b[0m\u001b[0m  \u001b[32m  ✓\u001b[0m\u001b[90m sets right flags from options\u001b[0m\u001b[31m (265ms)\u001b[0m


\u001b[92m \u001b[0m\u001b[32m 36 passing\u001b[0m\u001b[90m (16m)\u001b[0m
\u001b[36m \u001b[0m\u001b[36m 2 pending\u001b[0m
\u001b[31m  1 failing\u001b[0m

\u001b[0m  1) compile
       compiles a simple .EO program into Java bytecode .class files:

      \u001b[31mAssertionError [ERR_ASSERTION]: \u001b[37mEO objects registered in temp/test-compile/simple/target/eo-foreign.json\u001b[39m
\u001b[37mEO program assembled in %s in 22s\u001b[39m
\u001b[37mEO program verified in temp/test-compile/simple/target\u001b[39m
\u001b[37mJava sources generated in temp/test-compile/simple/target/generated-sources\u001b[39m
\u001b[37mJava .class files compiled into temp/test-compile/simple/target\u001b[39m

File /home/r/repo/temp/test-compile/simple/target/generated-sources/EOfoo/EObar/EOcompile.java is absent\u001b[0m
      \u001b[32m+ expected\u001b[0m \u001b[31m- actual\u001b[0m

      \u001b[31m-false\u001b[0m
      \u001b[32m+true\u001b[0m
      \u001b[0m\u001b[90m
      at /home/r/repo/test/helpers.js:73:5
      at Array.forEach (<anonymous>)
      at assertFilesExist (test/helpers.js:71:9)
      at Context.<anonymous> (test/commands/test_compile.js:45:5)
      at process.processImmediate (node:internal/timers:476:21)
\u001b[0m


Warning:  Use --force to continue.

Aborted due to warnings.
container 5b0a2aed8524f2e3df0a49eb596f92ab72aaa5dec1ed9db5b6090e12cf60e642 is dead
Thu Nov 28 10:46:34 UTC 2024

@yegor256
Copy link
Member

@rultor merge

@rultor
Copy link
Contributor

rultor commented Nov 28, 2024

@rultor merge

@yegor256 OK, I'll try to merge now. You can check the progress of the merge here.

@rultor
Copy link
Contributor

rultor commented Nov 28, 2024

@rultor merge

@trapvpack @yegor256 Oops, I failed. You can see the full log here (spent 22min).

              ^

Error: Command failed: node /home/r/repo/node_modules/eo2js/src/eo2js.js transpile --target /home/r/repo/temp/test-transpile/js/target --project project --foreign eo-foreign.json --resources /home/r/repo/node_modules/eo2js/src/resources --alone
    at checkExecSyncError (node:child_process:890:11)
    at execSync (node:child_process:962:15)
    at /home/r/repo/src/eo2jsw.js:31:5
    at new Promise (<anonymous>)
    at eo2jsw (/home/r/repo/src/eo2jsw.js:30:10)
    at module.exports [as transpile] (/home/r/repo/src/commands/js/transpile.js:35:10)
    at /home/r/repo/src/eoc.js:273:29
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 15118,
  stdout: null,
  stderr: null
}

Node.js v18.19.1
\u001b[0m\u001b[90m
  Error: Command failed: node /home/r/repo/src/eoc.js --batch transpile --verbose --parser=0.43.2 --home-tag=0.43.1 -s /home/r/repo/temp/test-transpile/js/src -t /home/r/repo/temp/test-transpile/js/target --language=JavaScript
  Cannot read properties of undefined (reading 'meta')
  node:internal/errors:865
    const err = new Error(message);
                ^
  
  Error: Command failed: node /home/r/repo/node_modules/eo2js/src/eo2js.js transpile --target /home/r/repo/temp/test-transpile/js/target --project project --foreign eo-foreign.json --resources /home/r/repo/node_modules/eo2js/src/resources --alone
      at checkExecSyncError (node:child_process:890:11)
      at execSync (node:child_process:962:15)
      at /home/r/repo/src/eo2jsw.js:31:5
      at new Promise (<anonymous>)
      at eo2jsw (src/eo2jsw.js:30:10)
      at module.exports [as transpile] (src/commands/js/transpile.js:35:10)
      at /home/r/repo/src/eoc.js:273:29
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
    status: 1,
    signal: null,
    output: [ null, null, null ],
    pid: 15118,
    stdout: null,
    stderr: null
  }
  
  Node.js v18.19.1
  
      at checkExecSyncError (node:child_process:890:11)
      at execSync (node:child_process:962:15)
      at runSync (test/helpers.js:47:12)
      at transpile (test/commands/test_transpile.js:47:12)
      at Context.<anonymous> (test/commands/test_transpile.js:72:20)
      at process.processImmediate (node:internal/timers:476:21)
\u001b[0m


Warning:  Use --force to continue.

Aborted due to warnings.
container 8f27d12919a6252b3750668ceb919e8ac5726de4ccce9cf02996e3639670dfd3 is dead
Thu Nov 28 14:07:32 UTC 2024

@yegor256
Copy link
Member

@rultor merge

@rultor
Copy link
Contributor

rultor commented Nov 28, 2024

@rultor merge

@yegor256 OK, I'll try to merge now. You can check the progress of the merge here.

@rultor
Copy link
Contributor

rultor commented Nov 28, 2024

@rultor merge

@trapvpack @yegor256 Oops, I failed. You can see the full log here (spent 19min).

              ^

Error: Command failed: node /home/r/repo/node_modules/eo2js/src/eo2js.js transpile --target /home/r/repo/temp/test-transpile/js/target --project project --foreign eo-foreign.json --resources /home/r/repo/node_modules/eo2js/src/resources --alone
    at checkExecSyncError (node:child_process:890:11)
    at execSync (node:child_process:962:15)
    at /home/r/repo/src/eo2jsw.js:31:5
    at new Promise (<anonymous>)
    at eo2jsw (/home/r/repo/src/eo2jsw.js:30:10)
    at module.exports [as transpile] (/home/r/repo/src/commands/js/transpile.js:35:10)
    at /home/r/repo/src/eoc.js:273:29
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 15109,
  stdout: null,
  stderr: null
}

Node.js v18.19.1
\u001b[0m\u001b[90m
  Error: Command failed: node /home/r/repo/src/eoc.js --batch transpile --verbose --parser=0.43.2 --home-tag=0.43.1 -s /home/r/repo/temp/test-transpile/js/src -t /home/r/repo/temp/test-transpile/js/target --language=JavaScript
  Cannot read properties of undefined (reading 'meta')
  node:internal/errors:865
    const err = new Error(message);
                ^
  
  Error: Command failed: node /home/r/repo/node_modules/eo2js/src/eo2js.js transpile --target /home/r/repo/temp/test-transpile/js/target --project project --foreign eo-foreign.json --resources /home/r/repo/node_modules/eo2js/src/resources --alone
      at checkExecSyncError (node:child_process:890:11)
      at execSync (node:child_process:962:15)
      at /home/r/repo/src/eo2jsw.js:31:5
      at new Promise (<anonymous>)
      at eo2jsw (src/eo2jsw.js:30:10)
      at module.exports [as transpile] (src/commands/js/transpile.js:35:10)
      at /home/r/repo/src/eoc.js:273:29
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
    status: 1,
    signal: null,
    output: [ null, null, null ],
    pid: 15109,
    stdout: null,
    stderr: null
  }
  
  Node.js v18.19.1
  
      at checkExecSyncError (node:child_process:890:11)
      at execSync (node:child_process:962:15)
      at runSync (test/helpers.js:47:12)
      at transpile (test/commands/test_transpile.js:47:12)
      at Context.<anonymous> (test/commands/test_transpile.js:72:20)
      at process.processImmediate (node:internal/timers:476:21)
\u001b[0m


Warning:  Use --force to continue.

Aborted due to warnings.
container f4f40ed93fac54d76eb1474d415eb875ba9b6dbcd327b6255a52145b998b4889 is dead
Thu Nov 28 14:46:07 UTC 2024

@yegor256
Copy link
Member

@trapvpack @maxonfjvipon something is wrong here? Why it doesn't build after merge?

@maxonfjvipon
Copy link
Member

@yegor256 it seems something wrong with eo2js here, I'll check this out

@trapvpack
Copy link
Contributor Author

@maxonfjvipon is there anything I can do to help?

@maxonfjvipon
Copy link
Member

maxonfjvipon commented Nov 30, 2024

@trapvpack let's wait for objectionary/eo2js#121, I'll fix it as quick as possible

@maxonfjvipon
Copy link
Member

@trapvpack I released new version of eo2js which works with EO 0.44.0, now let's wait for this PR to be merged and we can try to merge again

@yegor256
Copy link
Member

@rultor merge

@rultor
Copy link
Contributor

rultor commented Dec 16, 2024

@rultor merge

@yegor256 OK, I'll try to merge now. You can check the progress of the merge here.

@rultor
Copy link
Contributor

rultor commented Dec 16, 2024

@rultor merge

@trapvpack @yegor256 Oops, I failed. You can see the full log here (spent 22min).

\u001b[0m  transpile\u001b[0m
  \u001b[32m  ✓\u001b[0m\u001b[90m transpiles a simple .EO program to Java\u001b[0m\u001b[31m (53049ms)\u001b[0m
  \u001b[36m  - transpiles a simple .EO program to JavaScript\u001b[0m
  \u001b[32m  ✓\u001b[0m\u001b[90m attempts to transpile a simple .EO program to wrong platform\u001b[0m\u001b[31m (117ms)\u001b[0m

\u001b[0m  unphi\u001b[0m
  \u001b[32m  ✓\u001b[0m\u001b[90m converts PHI files to XMIR files\u001b[0m\u001b[31m (4629ms)\u001b[0m

\u001b[0m  elapsed\u001b[0m
task in 301ms
  \u001b[32m  ✓\u001b[0m\u001b[90m measures time correctly\u001b[0m\u001b[31m (302ms)\u001b[0m
short task in 10ms
  \u001b[32m  ✓\u001b[0m\u001b[90m measures short time correctly\u001b[0m
long task in 2s
  \u001b[32m  ✓\u001b[0m\u001b[90m measures long time correctly\u001b[0m\u001b[31m (1202ms)\u001b[0m
  \u001b[32m  ✓\u001b[0m\u001b[90m handles errors in task correctly\u001b[0m

\u001b[0m  eoc\u001b[0m
  \u001b[32m  ✓\u001b[0m\u001b[90m prints its own version\u001b[0m\u001b[31m (119ms)\u001b[0m
  \u001b[32m  ✓\u001b[0m\u001b[90m prints help screen\u001b[0m\u001b[31m (132ms)\u001b[0m

\u001b[0m  eoc\u001b[0m
  \u001b[32m  ✓\u001b[0m\u001b[90m loads latest version\u001b[0m\u001b[31m (458ms)\u001b[0m

\u001b[0m  mvnw\u001b[0m
+ /home/r/repo/mvnw/mvnw --version --quiet --batch-mode --color=never --update-snapshots --fail-fast --strict-checksums
  \u001b[32m  ✓\u001b[0m\u001b[90m prints Maven own version\u001b[0m
Sources in sources
Target in target
+ /home/r/repo/mvnw/mvnw --version --quiet -Deo.version=parser -Deo.tag=homeTag --quiet -Deo.sourcesDir=/home/r/repo/sources -Deo.targetDir=/home/r/repo/target -Deo.outputDir=/home/r/repo/target/classes -Deo.generatedDir=/home/r/repo/target/generated-sources -Deo.placed=/home/r/repo/target/eo-placed.csv -Deo.placedFormat=csv --batch-mode --color=never --update-snapshots --fail-fast --strict-checksums
\u001b[0m\u001b[0m\u001b[0m\u001b[0m3.9.9
\u001b[0m\u001b[0m3.9.9
\u001b[0m\u001b[0m  \u001b[32m  ✓\u001b[0m\u001b[90m sets right flags from options\u001b[0m\u001b[31m (302ms)\u001b[0m


\u001b[92m \u001b[0m\u001b[32m 39 passing\u001b[0m\u001b[90m (18m)\u001b[0m
\u001b[36m \u001b[0m\u001b[36m 4 pending\u001b[0m


Running "eslint:target" (eslint) task

Done.
+ mv /home/r/repo .
++ whoami
+ chown -R root repo
+ '[' -n '' ']'
++ whoami
+ sudo chown -R ubuntu repo
+ cd repo
+ git push origin master
To github.com:objectionary/eoc.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'github.com:objectionary/eoc.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
container 61c62a13a8b5950da4c1738b557d278ff6140461626b1919f2b411949a6e75f7 is dead
Mon Dec 16 17:05:47 UTC 2024

@yegor256 yegor256 merged commit 8a96695 into objectionary:master Dec 16, 2024
13 checks passed
@yegor256
Copy link
Member

@trapvpack thanks!!

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

Successfully merging this pull request may close these issues.

we don't show timing in the main log output
4 participants