Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(399)

Delta Between Two Patch Sets: environs/dummy/environs.go

Issue 6482081: environs/dummy: add delay (Closed)
Left Patch Set: environs/dummy: add delay Created 11 years, 7 months ago
Right Patch Set: environs/dummy: add delay Created 11 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « [revision details] ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // The dummy provider implements an environment provider for testing 1 // The dummy provider implements an environment provider for testing
2 // purposes, registered with environs under the name "dummy". 2 // purposes, registered with environs under the name "dummy".
3 //· 3 //·
4 // The configuration YAML for the testing environment 4 // The configuration YAML for the testing environment
5 // must specify a "zookeeper" property with a boolean 5 // must specify a "zookeeper" property with a boolean
6 // value. If this is true, a zookeeper instance will be started 6 // value. If this is true, a zookeeper instance will be started
7 // the first time StateInfo is called on a newly reset environment. 7 // the first time StateInfo is called on a newly reset environment.
8 // NOTE: ZooKeeper isn't actually being started yet. 8 // NOTE: ZooKeeper isn't actually being started yet.
9 //· 9 //·
10 // The configuration data also accepts a "broken" property 10 // The configuration data also accepts a "broken" property
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 name string 103 name string
104 ops chan<- Operation 104 ops chan<- Operation
105 mu sync.Mutex 105 mu sync.Mutex
106 maxId int // maximum instance id allocated so far. 106 maxId int // maximum instance id allocated so far.
107 insts map[string]*instance 107 insts map[string]*instance
108 ports map[int]map[state.Port]bool 108 ports map[int]map[state.Port]bool
109 bootstrapped bool 109 bootstrapped bool
110 storage *storage 110 storage *storage
111 publicStorage *storage 111 publicStorage *storage
112 httpListener net.Listener 112 httpListener net.Listener
113 delayTime time.Duration // delay before actioning request
niemeyer 2012/08/29 13:32:48 This variable is unused.
dfc 2012/08/29 23:14:12 Done.
114 } 113 }
115 114
116 // environ represents a client's connection to a given environment's 115 // environ represents a client's connection to a given environment's
117 // state. 116 // state.
118 type environ struct { 117 type environ struct {
119 state *environState 118 state *environState
120 ecfgMutex sync.Mutex 119 ecfgMutex sync.Mutex
121 ecfgUnlocked *environConfig 120 ecfgUnlocked *environConfig
122 } 121 }
123 122
124 // storage holds the storage for an environState. 123 // storage holds the storage for an environState.
125 // There are two instances for each environState 124 // There are two instances for each environState
126 // instance, one for public files and one for private. 125 // instance, one for public files and one for private.
127 type storage struct { 126 type storage struct {
128 path string // path prefix in http space. 127 path string // path prefix in http space.
129 state *environState 128 state *environState
130 files map[string][]byte 129 files map[string][]byte
131 } 130 }
132 131
133 var ( 132 // discardOperations discards all Operations written to it.
134 » // discardOperations discards all Operations written to it. 133 var discardOperations chan<- Operation
135 » discardOperations chan<- Operation
136
137 » // providerDelay controls the delay before dummy responds.
138 » // non empty values in JUJU_DUMMY_DELAY will be parsed as·
139 » // time.Durations into this value.
140 » providerDelay time.Duration
141 )
142 134
143 func init() { 135 func init() {
144 environs.RegisterProvider("dummy", &providerInstance) 136 environs.RegisterProvider("dummy", &providerInstance)
145 137
146 // Prime the first ops channel, so that naive clients can use 138 // Prime the first ops channel, so that naive clients can use
147 // the testing environment by simply importing it. 139 // the testing environment by simply importing it.
148 c := make(chan Operation) 140 c := make(chan Operation)
149 go func() { 141 go func() {
150 for _ = range c { 142 for _ = range c {
151 } 143 }
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 } 579 }
588 inst.state.mu.Lock() 580 inst.state.mu.Lock()
589 defer inst.state.mu.Unlock() 581 defer inst.state.mu.Unlock()
590 for p := range inst.ports { 582 for p := range inst.ports {
591 ports = append(ports, p) 583 ports = append(ports, p)
592 } 584 }
593 state.SortPorts(ports) 585 state.SortPorts(ports)
594 return 586 return
595 } 587 }
596 588
589 // providerDelay controls the delay before dummy responds.
590 // non empty values in JUJU_DUMMY_DELAY will be parsed as·
591 // time.Durations into this value.
592 var providerDelay time.Duration
593
597 // pause execution to simulate the latency of a real provider 594 // pause execution to simulate the latency of a real provider
niemeyer 2012/08/29 13:32:48 I'd pull down the variable and init function excer
dfc 2012/08/29 23:14:12 Done.
598 func delay() { 595 func delay() {
599 if providerDelay > 0 { 596 if providerDelay > 0 {
600 log.Printf("dummy: pausing for %v", providerDelay) 597 log.Printf("dummy: pausing for %v", providerDelay)
601 <-time.After(providerDelay) 598 <-time.After(providerDelay)
602 } 599 }
603 } 600 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b