Skip to content
This repository was archived by the owner on May 6, 2020. It is now read-only.

Conversation

@devimc
Copy link

@devimc devimc commented May 3, 2017

With this commit kill command is able to handle numeric
signals as argument

Signed-off-by: Julio Montes julio.montes@intel.com

@devimc devimc requested review from jodh-intel and sboeuf May 3, 2017 13:53
kill.go Outdated
for _, v := range signals {
if v == signum {
// signal is a valid signal
if err := vc.KillContainer(containerID, podStatus.ContainersStatus[0].ID, signum); err != nil {

Choose a reason for hiding this comment

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

I'd prefer only a single call to vc.KillContainer() if possible.

Also, note #109 if you want to pick that up?

Copy link
Author

Choose a reason for hiding this comment

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

yep, I'll take this issue

Copy link
Contributor

@sboeuf sboeuf left a comment

Choose a reason for hiding this comment

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

The implementation seems good to me but I have two requests:

  • Could you please create a separate function doing this processing about the signal:
func processSignal(signal string) (syscall.Signal, error)

and then call it from the current kill() function so that you actually only add

processedSignal, err := processSignal(signal)
if err != nil {
        return err
}

before the call to vc.KillContainer()

  • And could you add the corresponding unit test to the function you've added.

kill.go Outdated
}

if err := vc.KillContainer(containerID, podStatus.ContainersStatus[0].ID, signals[signal]); err != nil {
signum, signalOk := signals[signal]
Copy link
Contributor

@dlespiau dlespiau May 3, 2017

Choose a reason for hiding this comment

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

You have the same code repeated twice now with some somewhat deep nested indentation.

				if err := vc.KillContainer(containerID, podStatus.ContainersStatus[0].ID, signum); err != nil {
					return err
				}
				return nil
  1. resolve the argument to get a signal number
  2. do the KillContainer call

For 1. we don't actually have to cycle through the map, we can just test if the signal is between 1 and 31 (or SIGHUP and SIGUNUSED).

@devimc devimc force-pushed the topic/fix_kill branch 2 times, most recently from 897762b to 468bebe Compare May 3, 2017 14:56
@devimc
Copy link
Author

devimc commented May 3, 2017

@jodh-intel @sboeuf @dlespiau Fixed
Thanks

@coveralls
Copy link

coveralls commented May 3, 2017

Coverage Status

Coverage increased (+1.5%) to 37.192% when pulling 468bebe on devimc:topic/fix_kill into 6c019a5 on clearcontainers:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+1.5%) to 37.192% when pulling 468bebe on devimc:topic/fix_kill into 6c019a5 on clearcontainers:master.

1 similar comment
@coveralls
Copy link

coveralls commented May 3, 2017

Coverage Status

Coverage increased (+1.5%) to 37.192% when pulling 468bebe on devimc:topic/fix_kill into 6c019a5 on clearcontainers:master.

"testing"
)

func TestProcessSignal(t *testing.T) {
Copy link
Contributor

@dlespiau dlespiau May 3, 2017

Choose a reason for hiding this comment

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

The usual thing here to limit the code to type and maintain is to use list the test cases in an array of structs (often using anonymous structs): https://dave.cheney.net/2013/06/09/writing-table-driven-tests-in-go

Copy link
Contributor

@dlespiau dlespiau May 3, 2017

Choose a reason for hiding this comment

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

something like

tests := []struct {
  input string
  valid bool
  golden syscall.Signal 
} {
 /* list of test cases */
}

for _, test := range tests {

 .....

}

An example at: https://github.com/dlespiau/x86db/blob/master/db_test.go#L10

Copy link
Contributor

Choose a reason for hiding this comment

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

Or another way is to actually create each test such as TestProcessSignalInvalidSignal(), TestProcessSignalInvalidShortSignal(), ... into a generic function like testProcessSignalFailure() or testProcessSignalSuccess().
That way each unit test has a name and it is very quick to get which test failed.

Copy link
Contributor

Choose a reason for hiding this comment

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

@sboeuf that adds quite a lot of typing and duplication actually. If the input needs some description, it can be added to the entries of the table, especially for very simple functions like that one that just take a string as input and return an int.

@dlespiau
Copy link
Contributor

dlespiau commented May 3, 2017

with the list of test cases input in a struct this is:

lgtm

Approved with PullApprove

Copy link
Contributor

@sboeuf sboeuf left a comment

Choose a reason for hiding this comment

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

Few changes needed, but this is much better :)

s, err := strconv.Atoi(signal)
if err != nil {
return 0, fmt.Errorf("Failed to convert signal %s to int", signal)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a new line please.

kill.go Outdated
return 0, fmt.Errorf("Failed to convert signal %s to int", signal)
}
signum = syscall.Signal(s)
// check whether signal is valid or not
Copy link
Contributor

Choose a reason for hiding this comment

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

s/check/Check/

// signal is a valid signal
return signum, nil
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a new line.

kill.go Outdated
}
signum = syscall.Signal(s)
// check whether signal is valid or not
for _, v := range signals {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe use "sig" instead of "v" because this will be easier to understand.

"testing"
)

func TestProcessSignal(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Or another way is to actually create each test such as TestProcessSignalInvalidSignal(), TestProcessSignalInvalidShortSignal(), ... into a generic function like testProcessSignalFailure() or testProcessSignalSuccess().
That way each unit test has a name and it is very quick to get which test failed.

@sboeuf
Copy link
Contributor

sboeuf commented May 3, 2017

Oh BTW @devimc could you please rebase recent changes from github.com/clearcontainers/runtime:origin/master so that Semaphore CI build can pass.

@devimc devimc force-pushed the topic/fix_kill branch from 468bebe to 317828d Compare May 3, 2017 15:47
kill_test.go Outdated
}

for _, test := range tests {
signum, _ := processSignal(test.signal)
Copy link
Contributor

Choose a reason for hiding this comment

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

you're missing testing we receive a non nil error on invalid input.

@coveralls
Copy link

coveralls commented May 3, 2017

Coverage Status

Coverage increased (+1.5%) to 37.192% when pulling 317828d on devimc:topic/fix_kill into 6c019a5 on clearcontainers:master.

Copy link
Contributor

@sboeuf sboeuf left a comment

Choose a reason for hiding this comment

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

After @dlespiau comment is addressed, this lgtm

@devimc devimc force-pushed the topic/fix_kill branch from 317828d to 6f51ef2 Compare May 3, 2017 16:27
@coveralls
Copy link

coveralls commented May 3, 2017

Coverage Status

Coverage increased (+1.5%) to 37.192% when pulling 6f51ef2 on devimc:topic/fix_kill into 6c019a5 on clearcontainers:master.

@devimc
Copy link
Author

devimc commented May 3, 2017

@dlespiau @sboeuf fixed

With this commit kill command is able to handle numeric
signals as argument

Fixes clearcontainers#109

Signed-off-by: Julio Montes <julio.montes@intel.com>
@devimc devimc force-pushed the topic/fix_kill branch from 6f51ef2 to 08db9ff Compare May 3, 2017 17:09
@dlespiau
Copy link
Contributor

dlespiau commented May 3, 2017

\o/

@coveralls
Copy link

coveralls commented May 3, 2017

Coverage Status

Coverage increased (+1.5%) to 37.192% when pulling 08db9ff on devimc:topic/fix_kill into 79541cd on clearcontainers:master.

@sboeuf sboeuf merged commit a246d4e into clearcontainers:master May 3, 2017
@devimc devimc deleted the topic/fix_kill branch May 24, 2017 14:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants