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

implement start operation tests #578

Merged
merged 1 commit into from
Feb 12, 2018
Merged

Conversation

liangchenye
Copy link
Member

Signed-off-by: Liang Chenye [email protected]

@liangchenye liangchenye mentioned this pull request Feb 8, 2018
44 tasks
@liangchenye
Copy link
Member Author

liangchenye commented Feb 8, 2018

  1. rename spec error code, 'NotCreated' is more accurate
    'StartNonCreateHaveNoEffect' to 'StartNotCreatedHaveNoEffect'
    'StartNonCreateGenError' to 'StartNotCreatedGenError'

  2. test the five cases of 'start' operation, two cases might be controversial

  • StartNotCreatedHaveNoEffect
    I understand it in this way: if a container is not 'created', the process should not be called again.
    So the output file MUST remain 'process called\n'
  • StartWithProcUnsetGenError
    In the spec, a runtime could apply some of the 'process' configs, so if 'process' is set to nil, this runtime might return an error. In this case, we can never reach 'StartWithProcUnsetGenError', so I skip this test if runtime fails in 'create' with nil process. Only if the runtime COULD create successfully, we can test this.

uuid "github.com/satori/go.uuid"
)

func wrap(t *tap.T, expected bool, specErr error, detailedErr error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is probably useful/generic enough to be a public function in validation/util/test.go. Maybe SpecErrorOk()?

r.Create()
// start a `created` container
err = r.Start()
outputData, _ := ioutil.ReadFile(output)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is racy. start should block until the user-specified program has executed, but there's no guarantee about how far along that program is in its execution. That means this read could be happening either before or after the user-specified program gets around to writing to output. The coarse guard for this would be to sleep for some safe-enough time. The better, but maybe Linux-specific, guard would be to use inotify(7) to block until the file was updated (or some safe-enough time had passed) and compare the measured write time with the start-invocation time (the write time should be after start was invoked and also after any prestart hooks completed).

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add time sleep here.

// must generate an error
wrap(t, err != nil, specerror.NewError(specerror.StartNotCreatedGenError, fmt.Errorf("attempting to `start` a container that is not `created` MUST generate an error"), rspecs.Version), err)

outputData, _ = ioutil.ReadFile(output)
Copy link
Contributor

Choose a reason for hiding this comment

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

You shouldn't be ignoring the returned error here (or in your other ReadFile calls). If one of those errors, you can die with a non-zero exit. node-tap will complain about that:

$ cat validation/test 
#!/bin/sh
cat <<EOF
TAP version 13
ok 1 - ok
EOF
exit 1
$ tap ./validation/test 
./validation/test ..................................... 1/2
  not ok ./validation/test
    timeout: 30000
    file: ./validation/test
    command: ./validation/test
    args: []
    stdio:
      - 0
      - pipe
      - 2
    cwd: /home/wking/.local/lib/go/src/github.com/opencontainers/runtime-tools
    failures:
      - tapError: no plan
    exitCode: 1

// must have no effect, it will not be something like 'process called\nprocess called\n'
wrap(t, string(outputData) == "process called\n", specerror.NewError(specerror.StartNotCreatedHaveNoEffect, fmt.Errorf("attempting to `start` a container that is not `created` MUST have no effect on the container"), rspecs.Version), err)

r.Delete()
Copy link
Contributor

Choose a reason for hiding this comment

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

You have another ignored error here.

g.Spec().Process = nil
r.SetConfig(g)
err = r.Create()
// 'create' could fail according to the spec when the process is nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Why “could fail”? Is this the “create can fail whenever it wants” loophole (opencontainers/runtime-spec#813, opencontainers/runtime-spec#927)? I don't see a need to call that out in this particular case. If we want, we could adjust our Create wrapper to handle this in all cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

If the process is nil, the config.json is invalid. It is up to the runtime to validate it in the 'create' since: The runtime MAY validate config.json against this spec.

If a runtime validates config.json in 'create', it might return error. In this case, the container is not created, we can never test 'StartWithProcUnsetGenError'. That is why I use 'Skip' in this case.

Copy link
Contributor

Choose a reason for hiding this comment

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

If the process is nil, the config.json is invalid.

That's not true since opencontainers/runtime-spec#701, which was part of runtime-spec v1.0.0-rc6 and later.

Copy link
Member Author

Choose a reason for hiding this comment

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

go it.

@liangchenye liangchenye force-pushed the master branch 3 times, most recently from 7934064 to 3ba4371 Compare February 9, 2018 05:23
@liangchenye
Copy link
Member Author

updated

  1. add a new SpecErrorOK function to util/test.go
  2. check unexpected errors

The 'StartWithProcUnsetGenError' is not changed, I replied in @wking 's comment.

@liangchenye
Copy link
Member Author

updated PTAL @q384566678 @wking

@zhouhao3
Copy link

zhouhao3 commented Feb 12, 2018

LGTM

Approved with PullApprove

@zhouhao3 zhouhao3 merged commit 9d9aab0 into opencontainers:master Feb 12, 2018
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.

3 participants