~ubuntu-branches/ubuntu/saucy/juju-core/saucy-proposed

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/testing/locking_test.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-07-11 17:18:27 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130711171827-vjqkg40r0dlf7ys2
Tags: 1.11.2-0ubuntu1
* New upstream release.
* Make juju-core the default juju (LP: #1190634):
  - d/control: Add virtual package juju -> juju-core.
  - d/juju-core.postinst.in: Bump priority of alternatives over that of
    python juju packages.
* Enable for all architectures (LP: #1172505):
  - d/control: Version BD on golang-go to >= 2:1.1.1 to ensure CGO
    support for non-x86 archs, make juju-core Arch: any.
  - d/README.source: Dropped - no longer required.
* d/watch: Updated for new upstream tarball naming.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2013 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package testing
 
5
 
 
6
import (
 
7
        "errors"
 
8
        . "launchpad.net/gocheck"
 
9
        "sync"
 
10
)
 
11
 
 
12
type LockingSuite struct{}
 
13
 
 
14
var _ = Suite(&LockingSuite{})
 
15
 
 
16
func (LockingSuite) TestTestLockingFunctionPassesCorrectLock(c *C) {
 
17
        lock := sync.Mutex{}
 
18
        function := func() {
 
19
                lock.Lock()
 
20
                lock.Unlock()
 
21
        }
 
22
        // TestLockingFunction succeeds.
 
23
        TestLockingFunction(&lock, function)
 
24
}
 
25
 
 
26
func (LockingSuite) TestTestLockingFunctionDetectsDisobeyedLock(c *C) {
 
27
        lock := sync.Mutex{}
 
28
        function := func() {}
 
29
        c.Check(
 
30
                func() { TestLockingFunction(&lock, function) },
 
31
                Panics,
 
32
                errors.New("function did not obey lock"))
 
33
}
 
34
 
 
35
func (LockingSuite) TestTestLockingFunctionDetectsFailureToReleaseLock(c *C) {
 
36
        lock := sync.Mutex{}
 
37
        defer lock.Unlock()
 
38
        function := func() {
 
39
                lock.Lock()
 
40
        }
 
41
        c.Check(
 
42
                func() { TestLockingFunction(&lock, function) },
 
43
                Panics,
 
44
                errors.New("function did not release lock"))
 
45
}