Open yegor256 opened 11 years ago
migrated from Trac, where originally posted by yegor256 on 12-Mar-2010 7:51pm
and we shall accept params:
#!php
<?php
class MyTest extends PhpRack_Test
{
public function testProcesses()
{
$options = array(
'order' => 'cpu', // order by CPU usage, biggest on top
'max' => 10, // maximum show 10 processes
);
// view full list of processes on the server
$this->assert->shell->ps($options);
}
}
migrated from Trac, where originally posted by yegor256 on 16-Mar-2010 2:44pm
can you do this? if yes, please estimate the task. don't forget about unit tests.
migrated from Trac, where originally posted by kkamkou on 16-Mar-2010 4:41pm
sure, 1h +1h, after ticket #15
migrated from Trac, where originally posted by yegor256 on 16-Mar-2010 6:16pm
agree, go ahead, any time.
migrated from Trac, where originally posted by kkamkou on 17-Mar-2010 10:06pm
i'll use "ps -ef" this command and args work in all os. is it ok?
migrated from Trac, where originally posted by yegor256 on 18-Mar-2010 8:27am
are you sure that ps
command is available in windows?
migrated from Trac, where originally posted by kkamkou on 18-Mar-2010 9:09am
for windows we must use com and wmi or "tasklist". But as i wrote, we need some kind of layer for windows and unix.
Mb we can create layer for shell commands? For example:
phpRack/Os/Abstaract.php phpRack/Os/Windows.php (wmi parsing function) phpRack/Os/Unix.php (os depended differences) phpRack/Os/Cmd.php (factory)
then just call: $cmd = new phpRack_Os_Cmd(something);
What do you think?
migrated from Trac, where originally posted by yegor256 on 18-Mar-2010 9:31am
good idea, but the negative side of it is that this factory will be used only once. I mean that ps
command is required only by this phpRack package, nobody else will use this command from a factory.
thus, it won't be a factory, but a lost cohesion between our packages and real system commands to be executed…
but let's think about it more..
so far, let's implement this package for unix only, if you can't make it for both (unix and windows). if we later decide to introduce the factory you suggested - we can easily do this.
migrated from Trac, where originally posted by kkamkou on 18-Mar-2010 10:16am
It's up to you
For windows it's 1h + 1h For unix it's 2h + 1h
migrated from Trac, where originally posted by yegor256 on 18-Mar-2010 3:15pm
ok, let's do it for unix only. go ahead.
migrated from Trac, where originally posted by kkamkou on 19-Mar-2010 1:40pm
rev r135
migrated from Trac, where originally posted by yegor256 on 23-Mar-2010 4:33pm
this is what I see:
FILE: /code/phpRack/phpRack/Package/Shell.php
--------------------------------------------------------------------------------
FOUND 62 ERROR(S) AFFECTING 57 LINE(S)
--------------------------------------------------------------------------------
43 | ERROR | Variable "_cmd_ps" is not in valid camel caps format
50 | ERROR | Variable "_cmd_alt" is not in valid camel caps format
63 | ERROR | Spaces must be used to indent lines; tabs are not allowed
65 | ERROR | Spaces must be used to indent lines; tabs are not allowed
66 | ERROR | Spaces must be used to indent lines; tabs are not allowed
67 | ERROR | Spaces must be used to indent lines; tabs are not allowed
68 | ERROR | Spaces must be used to indent lines; tabs are not allowed
70 | ERROR | Spaces must be used to indent lines; tabs are not allowed
70 | ERROR | Variable "_cmd_ps" is not in valid camel caps format
72 | ERROR | Spaces must be used to indent lines; tabs are not allowed
73 | ERROR | Spaces must be used to indent lines; tabs are not allowed
74 | ERROR | Spaces must be used to indent lines; tabs are not allowed
75 | ERROR | Spaces must be used to indent lines; tabs are not allowed
77 | ERROR | Spaces must be used to indent lines; tabs are not allowed
79 | ERROR | Spaces must be used to indent lines; tabs are not allowed
80 | ERROR | Spaces must be used to indent lines; tabs are not allowed
81 | ERROR | Spaces must be used to indent lines; tabs are not allowed
82 | ERROR | Spaces must be used to indent lines; tabs are not allowed
84 | ERROR | Spaces must be used to indent lines; tabs are not allowed
86 | ERROR | Spaces must be used to indent lines; tabs are not allowed
87 | ERROR | Spaces must be used to indent lines; tabs are not allowed
88 | ERROR | Spaces must be used to indent lines; tabs are not allowed
90 | ERROR | Spaces must be used to indent lines; tabs are not allowed
91 | ERROR | Spaces must be used to indent lines; tabs are not allowed
93 | ERROR | Spaces must be used to indent lines; tabs are not allowed
94 | ERROR | Spaces must be used to indent lines; tabs are not allowed
96 | ERROR | Spaces must be used to indent lines; tabs are not allowed
97 | ERROR | Spaces must be used to indent lines; tabs are not allowed
97 | ERROR | Variable "_cmd_alt" is not in valid camel caps format
99 | ERROR | Spaces must be used to indent lines; tabs are not allowed
100 | ERROR | Spaces must be used to indent lines; tabs are not allowed
101 | ERROR | Spaces must be used to indent lines; tabs are not allowed
102 | ERROR | Spaces must be used to indent lines; tabs are not allowed
104 | ERROR | Spaces must be used to indent lines; tabs are not allowed
106 | ERROR | Spaces must be used to indent lines; tabs are not allowed
108 | ERROR | Spaces must be used to indent lines; tabs are not allowed
109 | ERROR | Spaces must be used to indent lines; tabs are not allowed
111 | ERROR | Spaces must be used to indent lines; tabs are not allowed
112 | ERROR | Spaces must be used to indent lines; tabs are not allowed
114 | ERROR | Spaces must be used to indent lines; tabs are not allowed
116 | ERROR | Spaces must be used to indent lines; tabs are not allowed
116 | ERROR | Variable "new_array" is not in valid camel caps format
118 | ERROR | Spaces must be used to indent lines; tabs are not allowed
119 | ERROR | Spaces must be used to indent lines; tabs are not allowed
120 | ERROR | Spaces must be used to indent lines; tabs are not allowed
121 | ERROR | Spaces must be used to indent lines; tabs are not allowed
123 | ERROR | Spaces must be used to indent lines; tabs are not allowed
123 | ERROR | Variable "new_array" is not in valid camel caps format
124 | ERROR | Spaces must be used to indent lines; tabs are not allowed
126 | ERROR | Spaces must be used to indent lines; tabs are not allowed
126 | ERROR | Variable "new_array" is not in valid camel caps format
127 | ERROR | Spaces must be used to indent lines; tabs are not allowed
128 | ERROR | Spaces must be used to indent lines; tabs are not allowed
130 | ERROR | Spaces must be used to indent lines; tabs are not allowed
131 | ERROR | Spaces must be used to indent lines; tabs are not allowed
132 | ERROR | Spaces must be used to indent lines; tabs are not allowed
133 | ERROR | Spaces must be used to indent lines; tabs are not allowed
135 | ERROR | Spaces must be used to indent lines; tabs are not allowed
136 | ERROR | Spaces must be used to indent lines; tabs are not allowed
137 | ERROR | Spaces must be used to indent lines; tabs are not allowed
139 | ERROR | Spaces must be used to indent lines; tabs are not allowed
141 | ERROR | Spaces must be used to indent lines; tabs are not allowed
--------------------------------------------------------------------------------
FILE: /code/phpRack/test/integration-tests/ShellTest.php
--------------------------------------------------------------------------------
FOUND 6 ERROR(S) AFFECTING 6 LINE(S)
--------------------------------------------------------------------------------
10 | ERROR | Spaces must be used to indent lines; tabs are not allowed
11 | ERROR | Spaces must be used to indent lines; tabs are not allowed
12 | ERROR | Spaces must be used to indent lines; tabs are not allowed
13 | ERROR | Spaces must be used to indent lines; tabs are not allowed
15 | ERROR | Spaces must be used to indent lines; tabs are not allowed
16 | ERROR | Spaces must be used to indent lines; tabs are not allowed
--------------------------------------------------------------------------------
FILE: /code/phpRack/test/phpRack/Package/ShellTest.php
--------------------------------------------------------------------------------
FOUND 21 ERROR(S) AFFECTING 20 LINE(S)
--------------------------------------------------------------------------------
32 | ERROR | Spaces must be used to indent lines; tabs are not allowed
33 | ERROR | Spaces must be used to indent lines; tabs are not allowed
34 | ERROR | Spaces must be used to indent lines; tabs are not allowed
35 | ERROR | Spaces must be used to indent lines; tabs are not allowed
36 | ERROR | Spaces must be used to indent lines; tabs are not allowed
44 | ERROR | Spaces must be used to indent lines; tabs are not allowed
46 | ERROR | Spaces must be used to indent lines; tabs are not allowed
47 | ERROR | Spaces must be used to indent lines; tabs are not allowed
48 | ERROR | Spaces must be used to indent lines; tabs are not allowed
50 | ERROR | Spaces must be used to indent lines; tabs are not allowed
51 | ERROR | Spaces must be used to indent lines; tabs are not allowed
52 | ERROR | Spaces must be used to indent lines; tabs are not allowed
53 | ERROR | Multi-line function call not indented correctly; expected 9
| | spaces but found 6
53 | ERROR | Spaces must be used to indent lines; tabs are not allowed
54 | ERROR | Spaces must be used to indent lines; tabs are not allowed
56 | ERROR | Spaces must be used to indent lines; tabs are not allowed
61 | ERROR | Spaces must be used to indent lines; tabs are not allowed
62 | ERROR | Spaces must be used to indent lines; tabs are not allowed
63 | ERROR | Spaces must be used to indent lines; tabs are not allowed
64 | ERROR | Spaces must be used to indent lines; tabs are not allowed
65 | ERROR | Spaces must be used to indent lines; tabs are not allowed
--------------------------------------------------------------------------------
Execution of target "phpcs" failed for the following reason: /code/phpRack/build.xml:54:10: Task exited with code 1
did you validate your change with phing?
migrated from Trac, where originally posted by kkamkou on 24-Mar-2010 12:40pm
Nope, sorry.
Checked by "Code Sniffer: and Zend standards (r185)
migrated from Trac, where originally posted by yegor256 on 24-Mar-2010 3:06pm
I get this:
phpRack tests > test:
[coverage-setup] Setting up coverage database for 26 files
[phpunit] Testsuite: Adapters_Db_MysqlTest
[phpunit] Tests run: 2, Failures: 0, Errors: 0, Incomplete: 0, Skipped: 0, Time elapsed: 0.35385 s
[phpunit] Testsuite: Adatpers_UrlTest
[phpunit] Tests run: 1, Failures: 0, Errors: 0, Incomplete: 1, Skipped: 0, Time elapsed: 0.00601 s
[phpunit] testWeCanCreateUrlAndCheckItsContent INCOMPLETE
[phpunit] Testsuite: BootstrapTest
[phpunit] Tests run: 2, Failures: 0, Errors: 0, Incomplete: 0, Skipped: 0, Time elapsed: 0.04597 s
phpRack error (2): mysql_connect(): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known, in /code/phpRack/phpRack/Adapters/Db/Mysql.php [line:75]phpRack error (2): mysql_connect(): [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servn (trying to connect via tcp://invalidHost:3306), in /code/phpRack/phpRack/Adapters/Db/Mysql.php [line:75]phpRack error (2): mysql_connect(): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known, in /code/phpRack/phpRack/Adapters/Db/Mysql.php [line:75]Exception: You must call dbExists() method before [phpunit] Testsuite: phpRack_Package_Db_MysqlTest
[phpunit] Tests run: 6, Failures: 0, Errors: 0, Incomplete: 0, Skipped: 0, Time elapsed: 0.06888 s
[phpunit] Testsuite: phpRack_Package_Disc_FileTest
[phpunit] Tests run: 14, Failures: 0, Errors: 0, Incomplete: 0, Skipped: 0, Time elapsed: 0.13180 s
[phpunit] Testsuite: phpRack_Package_Php_LintTest
[phpunit] Tests run: 4, Failures: 0, Errors: 0, Incomplete: 0, Skipped: 0, Time elapsed: 1.22469 s
[phpunit] Testsuite: phpRack_Package_ShellTest::testPs
[phpunit] Tests run: 4, Failures: 4, Errors: 0, Incomplete: 0, Skipped: 0, Time elapsed: 0.03281 s
[phpunit] testPs with data set #0 FAILED
[phpunit] OS not supported
[phpunit] /code/phpRack/test/phpRack/Package/ShellTest.php:51
[phpunit] /usr/local/PEAR/phing.php:37
[phpunit] testPs with data set #1 FAILED
[phpunit] OS not supported
[phpunit] /code/phpRack/test/phpRack/Package/ShellTest.php:51
[phpunit] /usr/local/PEAR/phing.php:37
[phpunit] testPs with data set #2 FAILED
[phpunit] OS not supported
[phpunit] /code/phpRack/test/phpRack/Package/ShellTest.php:51
[phpunit] /usr/local/PEAR/phing.php:37
[phpunit] testPs with data set #3 FAILED
[phpunit] OS not supported
[phpunit] /code/phpRack/test/phpRack/Package/ShellTest.php:51
[phpunit] /usr/local/PEAR/phing.php:37
[phpunit] Testsuite: AuthResultTest
[phpunit] Tests run: 1, Failures: 0, Errors: 0, Incomplete: 0, Skipped: 0, Time elapsed: 0.00670 s
phpRack error (2): mysql_connect(): Access denied for user 'fazend_phprack'@'localhost' (using password: YES), in /code/phpRack/phpRack/Adapters/Db/Mysql.php [line:75]phpRack error (2): finfo::file(): The invalid fileinfo object., in /code/phpRack/phpRack/Package/Php/Extensions/Fileinfo.php [line:49] [phpunit] Testsuite: RunnerTest
[phpunit] Tests run: 6, Failures: 0, Errors: 0, Incomplete: 0, Skipped: 0, Time elapsed: 2.11594 s
[phpunit] Testsuite: ViewTest
[phpunit] Tests run: 1, Failures: 0, Errors: 0, Incomplete: 0, Skipped: 0, Time elapsed: 0.01683 s
[phpunit] Tests run: 42, Failures: 4, Errors: 0, Incomplete: 1, Skipped: 0, Time elapsed: 4.35760 s
Execution of target "test" failed for the following reason: /code/phpRack/build.xml:90:63: Test FAILURE (testPs with data set #3): OS not supported
BUILD FAILED
I have MacOS. Would be nice to report the OS, if it's not supported.
migrated from Trac, where originally posted by kkamkou on 24-Mar-2010 6:36pm
if you plan to close "todo" entries, it will be corrected next iteration of this ticket.
migrated from Trac, where originally posted by yegor256 on 24-Mar-2010 7:17pm
before I can start working with the code, I need to be able to merge your change with trunk. and so far I can't do it, since unit tests are broken. please, correct your tests, and then revert back this ticket to me. I will merge your changes with trunk, and then will try to resolve @todo
marks, if they exists.
migrated from Trac, where originally posted by yegor256 on 30-Mar-2010 10:48am
any news here? ready to return the branch?
migrated from Trac, where originally posted by kk on 30-Mar-2010 2:26pm
Unit-testing is code-stress-check. In this situation, you must close all todo entries and only then check unit tests.
Current status is that test returns false, because code will produce unexpected results on your os(macos). And this situation is correct.
migrated from Trac, where originally posted by yegor256 on 30-Mar-2010 3:05pm
please, read this concept: PDD. the idea is that you always return a testable branch, which I merge with trunk, and then decide what to do with @todo
tags — how to resolve them and when. you should use stubs in the code, when necessary. but we can never merge the branch with trunk if it's not build-able.
please, try to make it working, use stubs where necessary and return the branch back to me. I will merge it with trunk. and we continue from there.
migrated from Trac, where originally posted by kkamkou on 31-Mar-2010 7:08am
Yegor, could you attach(macos) output for: "ps -ef" and then "ps -eo pid,pcpu | awk 'NR>1{print $1","$2}'". Then for: ps -eo pid,pmem | awk 'NR>1{print $1","$2}'
"please, read this concept". You are working with freelancers. And main things for them(for me) is to change work time with money. "return a testable branch" - it req. time to fix todo entry to provide you working version on your os. it's like cycle.
migrated from Trac, where originally posted by kkamkou on 31-Mar-2010 7:10am
p.s. and "cat /proc/stat" (if it exists)
migrated from Trac, where originally posted by yegor256 on 31-Mar-2010 7:50am
the idea of PDD is that you should not implement everything, but inject stubs in the code, just to make sure it is buildable. in our example, you just return some empty string if MacOS is detected (or any other OS), and make sure that all tests work properly. where you use stubs - put @todo
tags, so that I know that you didn't implement this place yet, but we have just a placeholder.
the goal is to return the branch back to me as soon as possible (preferably in 30-40 minutes), and let me handle the @todo
tags. let's try, you will see how easy it is and how effectively you can use your time (which is money, first of all).
migrated from Trac, where originally posted by kkamkou on 31-Mar-2010 10:01am
r243
migrated from Trac, where originally posted by yegor256 on 31-Mar-2010 10:54am
there are a few problems with this class (source:/branches/ticket_11/phpRack/Package/ShellTest.php):
@todo
tag into the method/class you expect me to change for you, in order to enable the finish of this taskstatic
in PHPUnit$this->markTestIncomplete()
please review and correct.
migrated from Trac, where originally posted by kkamkou on 31-Mar-2010 11:09am
migrated from Trac, where originally posted by yegor256 on 31-Mar-2010 12:02pm
I don't check the code manually, phing
script does it. Just run phing
in the directory of the project and you will see the problems. We ignore PHPCS warnings (-n
option is in place). The problem was with indentation, not with long lines. Lines are allowed if they are shorter than 120 symbols.
My fault about data providers, sorry. I had a feeling that they should be static..
I have a concern about the design of the method. It works OK now, when we have one operating system and only one fixed set of options. What will happen when we decide to add more OS's and more options? I feel that the method will grow (now it's rather long already) and will turn into mess. we should design it differently, using adapters, like:
!#php
<?php
class phpRack_Package_Shell extends phpRack_Package {
public function ps($options)
{
$processes = phpRack_Adapters_Process::retrieveAll();
if ($options['order']) {
usort(
$processes,
create_function(
'$a, $b',
'return $a->memory > $b->memory;'
)
);
/* etc. */
}
}
}
and inside phpRack_Adapters_Process
adapter we will implement different mechanisms of getting full list of processes running on the server. for different operating systems. this approach sounds more object-oriented to me and more extendable in the future.
what do you think?
migrated from Trac, where originally posted by kkamkou on 1-Apr-2010 1:15pm
Agree. I have spent much time to work with different os like win, sunos, hp-ux and aix. Main problem is that mostly commands are similar. But params or output - different. On windows we have good news, because it has common standard.
I have small experience in class-arch, that's why it's up to you.
migrated from Trac, where originally posted by yegor256 on 8-Apr-2010 12:48pm
I will design classes shortly, hopefully today
migrated from Trac, where originally posted by yegor256 on 12-Mar-2010 1:28pm
We should implement this assertion:
as usual, this should work both in Linux and in Windows. we should see a full list of processes running now on the server.