How to use wait method of service Package

Best Selenoid code snippet using service.wait

docker_api_swarm_service_test.go

Source:docker_api_swarm_service_test.go Github

copy

Full Screen

...112 var daemons [nodeCount]*daemon.Daemon113 for i := 0; i < nodeCount; i++ {114 daemons[i] = s.AddDaemon(c, true, i == 0)115 }116 // wait for nodes ready117 poll.WaitOn(c, pollCheck(c, daemons[0].CheckNodeReadyCount, checker.Equals(nodeCount)), poll.WithTimeout(5*time.Second))118 // service image at start119 image1 := "busybox:latest"120 // target image in update121 image2 := "busybox:test"122 // create a different tag123 for _, d := range daemons {124 out, err := d.Cmd("tag", image1, image2)125 assert.NilError(c, err, out)126 }127 // create service128 instances := 5129 parallelism := 2130 rollbackParallelism := 3131 id := daemons[0].CreateService(c, serviceForUpdate, setInstances(instances))132 // wait for tasks ready133 poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))134 // issue service update135 service := daemons[0].GetService(c, id)136 daemons[0].UpdateService(c, service, setImage(image2))137 // first batch138 poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances - parallelism, image2: parallelism})), poll.WithTimeout(defaultReconciliationTimeout))139 // 2nd batch140 poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances - 2*parallelism, image2: 2 * parallelism})), poll.WithTimeout(defaultReconciliationTimeout))141 // 3nd batch142 poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image2: instances})), poll.WithTimeout(defaultReconciliationTimeout))143 // Roll back to the previous version. This uses the CLI because144 // rollback used to be a client-side operation.145 out, err := daemons[0].Cmd("service", "update", "--detach", "--rollback", id)146 assert.NilError(c, err, out)147 // first batch148 poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image2: instances - rollbackParallelism, image1: rollbackParallelism})), poll.WithTimeout(defaultReconciliationTimeout))149 // 2nd batch150 poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))151}152func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateStartFirst(c *testing.T) {153 d := s.AddDaemon(c, true, true)154 // service image at start155 image1 := "busybox:latest"156 // target image in update157 image2 := "testhealth:latest"158 // service started from this image won't pass health check159 result := cli.BuildCmd(c, image2, cli.Daemon(d),160 build.WithDockerfile(`FROM busybox161 HEALTHCHECK --interval=1s --timeout=30s --retries=1024 \162 CMD cat /status`),163 )164 result.Assert(c, icmd.Success)165 // create service166 instances := 5167 parallelism := 2168 rollbackParallelism := 3169 id := d.CreateService(c, serviceForUpdate, setInstances(instances), setUpdateOrder(swarm.UpdateOrderStartFirst), setRollbackOrder(swarm.UpdateOrderStartFirst))170 checkStartingTasks := func(expected int) []swarm.Task {171 var startingTasks []swarm.Task172 poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) {173 tasks := d.GetServiceTasks(c, id)174 startingTasks = nil175 for _, t := range tasks {176 if t.Status.State == swarm.TaskStateStarting {177 startingTasks = append(startingTasks, t)178 }179 }180 return startingTasks, ""181 }, checker.HasLen(expected)), poll.WithTimeout(defaultReconciliationTimeout))182 return startingTasks183 }184 makeTasksHealthy := func(tasks []swarm.Task) {185 for _, t := range tasks {186 containerID := t.Status.ContainerStatus.ContainerID187 d.Cmd("exec", containerID, "touch", "/status")188 }189 }190 // wait for tasks ready191 poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))192 // issue service update193 service := d.GetService(c, id)194 d.UpdateService(c, service, setImage(image2))195 // first batch196 // The old tasks should be running, and the new ones should be starting.197 startingTasks := checkStartingTasks(parallelism)198 poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))199 // make it healthy200 makeTasksHealthy(startingTasks)201 poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances - parallelism, image2: parallelism})), poll.WithTimeout(defaultReconciliationTimeout))202 // 2nd batch203 // The old tasks should be running, and the new ones should be starting.204 startingTasks = checkStartingTasks(parallelism)205 poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances - parallelism, image2: parallelism})), poll.WithTimeout(defaultReconciliationTimeout))206 // make it healthy207 makeTasksHealthy(startingTasks)208 poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances - 2*parallelism, image2: 2 * parallelism})), poll.WithTimeout(defaultReconciliationTimeout))209 // 3nd batch210 // The old tasks should be running, and the new ones should be starting.211 startingTasks = checkStartingTasks(1)212 poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances - 2*parallelism, image2: 2 * parallelism})), poll.WithTimeout(defaultReconciliationTimeout))213 // make it healthy214 makeTasksHealthy(startingTasks)215 poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image2: instances})), poll.WithTimeout(defaultReconciliationTimeout))216 // Roll back to the previous version. This uses the CLI because217 // rollback is a client-side operation.218 out, err := d.Cmd("service", "update", "--detach", "--rollback", id)219 assert.NilError(c, err, out)220 // first batch221 poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image2: instances - rollbackParallelism, image1: rollbackParallelism})), poll.WithTimeout(defaultReconciliationTimeout))222 // 2nd batch223 poll.WaitOn(c, pollCheck(c, d.CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))224}225func (s *DockerSwarmSuite) TestAPISwarmServicesFailedUpdate(c *testing.T) {226 const nodeCount = 3227 var daemons [nodeCount]*daemon.Daemon228 for i := 0; i < nodeCount; i++ {229 daemons[i] = s.AddDaemon(c, true, i == 0)230 }231 // wait for nodes ready232 poll.WaitOn(c, pollCheck(c, daemons[0].CheckNodeReadyCount, checker.Equals(nodeCount)), poll.WithTimeout(5*time.Second))233 // service image at start234 image1 := "busybox:latest"235 // target image in update236 image2 := "busybox:badtag"237 // create service238 instances := 5239 id := daemons[0].CreateService(c, serviceForUpdate, setInstances(instances))240 // wait for tasks ready241 poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))242 // issue service update243 service := daemons[0].GetService(c, id)244 daemons[0].UpdateService(c, service, setImage(image2), setFailureAction(swarm.UpdateFailureActionPause), setMaxFailureRatio(0.25), setParallelism(1))245 // should update 2 tasks and then pause246 poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceUpdateState(id), checker.Equals(swarm.UpdateStatePaused)), poll.WithTimeout(defaultReconciliationTimeout))247 v, _ := daemons[0].CheckServiceRunningTasks(id)(c)248 assert.Assert(c, v == instances-2)249 // Roll back to the previous version. This uses the CLI because250 // rollback used to be a client-side operation.251 out, err := daemons[0].Cmd("service", "update", "--detach", "--rollback", id)252 assert.NilError(c, err, out)253 poll.WaitOn(c, pollCheck(c, daemons[0].CheckRunningTaskImages, checker.DeepEquals(map[string]int{image1: instances})), poll.WithTimeout(defaultReconciliationTimeout))254}255func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintRole(c *testing.T) {256 const nodeCount = 3257 var daemons [nodeCount]*daemon.Daemon258 for i := 0; i < nodeCount; i++ {259 daemons[i] = s.AddDaemon(c, true, i == 0)260 }261 // wait for nodes ready262 poll.WaitOn(c, pollCheck(c, daemons[0].CheckNodeReadyCount, checker.Equals(nodeCount)), poll.WithTimeout(5*time.Second))263 // create service264 constraints := []string{"node.role==worker"}265 instances := 3266 id := daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))267 // wait for tasks ready268 poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceRunningTasks(id), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))269 // validate tasks are running on worker nodes270 tasks := daemons[0].GetServiceTasks(c, id)271 for _, task := range tasks {272 node := daemons[0].GetNode(c, task.NodeID)273 assert.Equal(c, node.Spec.Role, swarm.NodeRoleWorker)274 }275 // remove service276 daemons[0].RemoveService(c, id)277 // create service278 constraints = []string{"node.role!=worker"}279 id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))280 // wait for tasks ready281 poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceRunningTasks(id), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))282 tasks = daemons[0].GetServiceTasks(c, id)283 // validate tasks are running on manager nodes284 for _, task := range tasks {285 node := daemons[0].GetNode(c, task.NodeID)286 assert.Equal(c, node.Spec.Role, swarm.NodeRoleManager)287 }288 // remove service289 daemons[0].RemoveService(c, id)290 // create service291 constraints = []string{"node.role==nosuchrole"}292 id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))293 // wait for tasks created294 poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceTasks(id), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))295 // let scheduler try296 time.Sleep(250 * time.Millisecond)297 // validate tasks are not assigned to any node298 tasks = daemons[0].GetServiceTasks(c, id)299 for _, task := range tasks {300 assert.Equal(c, task.NodeID, "")301 }302}303func (s *DockerSwarmSuite) TestAPISwarmServiceConstraintLabel(c *testing.T) {304 const nodeCount = 3305 var daemons [nodeCount]*daemon.Daemon306 for i := 0; i < nodeCount; i++ {307 daemons[i] = s.AddDaemon(c, true, i == 0)308 }309 // wait for nodes ready310 poll.WaitOn(c, pollCheck(c, daemons[0].CheckNodeReadyCount, checker.Equals(nodeCount)), poll.WithTimeout(5*time.Second))311 nodes := daemons[0].ListNodes(c)312 assert.Equal(c, len(nodes), nodeCount)313 // add labels to nodes314 daemons[0].UpdateNode(c, nodes[0].ID, func(n *swarm.Node) {315 n.Spec.Annotations.Labels = map[string]string{316 "security": "high",317 }318 })319 for i := 1; i < nodeCount; i++ {320 daemons[0].UpdateNode(c, nodes[i].ID, func(n *swarm.Node) {321 n.Spec.Annotations.Labels = map[string]string{322 "security": "low",323 }324 })325 }326 // create service327 instances := 3328 constraints := []string{"node.labels.security==high"}329 id := daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))330 // wait for tasks ready331 poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceRunningTasks(id), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))332 tasks := daemons[0].GetServiceTasks(c, id)333 // validate all tasks are running on nodes[0]334 for _, task := range tasks {335 assert.Assert(c, task.NodeID == nodes[0].ID)336 }337 // remove service338 daemons[0].RemoveService(c, id)339 // create service340 constraints = []string{"node.labels.security!=high"}341 id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))342 // wait for tasks ready343 poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceRunningTasks(id), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))344 tasks = daemons[0].GetServiceTasks(c, id)345 // validate all tasks are NOT running on nodes[0]346 for _, task := range tasks {347 assert.Assert(c, task.NodeID != nodes[0].ID)348 }349 // remove service350 daemons[0].RemoveService(c, id)351 constraints = []string{"node.labels.security==medium"}352 id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))353 // wait for tasks created354 poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceTasks(id), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))355 // let scheduler try356 time.Sleep(250 * time.Millisecond)357 tasks = daemons[0].GetServiceTasks(c, id)358 // validate tasks are not assigned359 for _, task := range tasks {360 assert.Assert(c, task.NodeID == "")361 }362 // remove service363 daemons[0].RemoveService(c, id)364 // multiple constraints365 constraints = []string{366 "node.labels.security==high",367 fmt.Sprintf("node.id==%s", nodes[1].ID),368 }369 id = daemons[0].CreateService(c, simpleTestService, setConstraints(constraints), setInstances(instances))370 // wait for tasks created371 poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceTasks(id), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))372 // let scheduler try373 time.Sleep(250 * time.Millisecond)374 tasks = daemons[0].GetServiceTasks(c, id)375 // validate tasks are not assigned376 for _, task := range tasks {377 assert.Assert(c, task.NodeID == "")378 }379 // make nodes[1] fulfills the constraints380 daemons[0].UpdateNode(c, nodes[1].ID, func(n *swarm.Node) {381 n.Spec.Annotations.Labels = map[string]string{382 "security": "high",383 }384 })385 // wait for tasks ready386 poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceRunningTasks(id), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))387 tasks = daemons[0].GetServiceTasks(c, id)388 for _, task := range tasks {389 assert.Assert(c, task.NodeID == nodes[1].ID)390 }391}392func (s *DockerSwarmSuite) TestAPISwarmServicePlacementPrefs(c *testing.T) {393 const nodeCount = 3394 var daemons [nodeCount]*daemon.Daemon395 for i := 0; i < nodeCount; i++ {396 daemons[i] = s.AddDaemon(c, true, i == 0)397 }398 // wait for nodes ready399 poll.WaitOn(c, pollCheck(c, daemons[0].CheckNodeReadyCount, checker.Equals(nodeCount)), poll.WithTimeout(5*time.Second))400 nodes := daemons[0].ListNodes(c)401 assert.Equal(c, len(nodes), nodeCount)402 // add labels to nodes403 daemons[0].UpdateNode(c, nodes[0].ID, func(n *swarm.Node) {404 n.Spec.Annotations.Labels = map[string]string{405 "rack": "a",406 }407 })408 for i := 1; i < nodeCount; i++ {409 daemons[0].UpdateNode(c, nodes[i].ID, func(n *swarm.Node) {410 n.Spec.Annotations.Labels = map[string]string{411 "rack": "b",412 }413 })414 }415 // create service416 instances := 4417 prefs := []swarm.PlacementPreference{{Spread: &swarm.SpreadOver{SpreadDescriptor: "node.labels.rack"}}}418 id := daemons[0].CreateService(c, simpleTestService, setPlacementPrefs(prefs), setInstances(instances))419 // wait for tasks ready420 poll.WaitOn(c, pollCheck(c, daemons[0].CheckServiceRunningTasks(id), checker.Equals(instances)), poll.WithTimeout(defaultReconciliationTimeout))421 tasks := daemons[0].GetServiceTasks(c, id)422 // validate all tasks are running on nodes[0]423 tasksOnNode := make(map[string]int)424 for _, task := range tasks {425 tasksOnNode[task.NodeID]++426 }427 assert.Assert(c, tasksOnNode[nodes[0].ID] == 2)428 assert.Assert(c, tasksOnNode[nodes[1].ID] == 1)429 assert.Assert(c, tasksOnNode[nodes[2].ID] == 1)430}431func (s *DockerSwarmSuite) TestAPISwarmServicesStateReporting(c *testing.T) {432 testRequires(c, testEnv.IsLocalDaemon)433 testRequires(c, DaemonIsLinux)...

Full Screen

Full Screen

cluster_health.go

Source:cluster_health.go Github

copy

Full Screen

...20 level string21 local *bool22 masterTimeout string23 timeout string24 waitForActiveShards *int25 waitForNodes string26 waitForNoRelocatingShards *bool27 waitForStatus string28}29// NewClusterHealthService creates a new ClusterHealthService.30func NewClusterHealthService(client *Client) *ClusterHealthService {31 return &ClusterHealthService{32 client: client,33 indices: make([]string, 0),34 }35}36// Index limits the information returned to specific indices.37func (s *ClusterHealthService) Index(indices ...string) *ClusterHealthService {38 s.indices = append(s.indices, indices...)39 return s40}41// Level specifies the level of detail for returned information.42func (s *ClusterHealthService) Level(level string) *ClusterHealthService {43 s.level = level44 return s45}46// Local indicates whether to return local information. If it is true,47// we do not retrieve the state from master node (default: false).48func (s *ClusterHealthService) Local(local bool) *ClusterHealthService {49 s.local = &local50 return s51}52// MasterTimeout specifies an explicit operation timeout for connection to master node.53func (s *ClusterHealthService) MasterTimeout(masterTimeout string) *ClusterHealthService {54 s.masterTimeout = masterTimeout55 return s56}57// Timeout specifies an explicit operation timeout.58func (s *ClusterHealthService) Timeout(timeout string) *ClusterHealthService {59 s.timeout = timeout60 return s61}62// WaitForActiveShards can be used to wait until the specified number of shards are active.63func (s *ClusterHealthService) WaitForActiveShards(waitForActiveShards int) *ClusterHealthService {64 s.waitForActiveShards = &waitForActiveShards65 return s66}67// WaitForNodes can be used to wait until the specified number of nodes are available.68// Example: "12" to wait for exact values, ">12" and "<12" for ranges.69func (s *ClusterHealthService) WaitForNodes(waitForNodes string) *ClusterHealthService {70 s.waitForNodes = waitForNodes71 return s72}73// WaitForNoRelocatingShards can be used to wait until all shard relocations are finished.74func (s *ClusterHealthService) WaitForNoRelocatingShards(waitForNoRelocatingShards bool) *ClusterHealthService {75 s.waitForNoRelocatingShards = &waitForNoRelocatingShards76 return s77}78// WaitForStatus can be used to wait until the cluster is in a specific state.79// Valid values are: green, yellow, or red.80func (s *ClusterHealthService) WaitForStatus(waitForStatus string) *ClusterHealthService {81 s.waitForStatus = waitForStatus82 return s83}84// WaitForGreenStatus will wait for the "green" state.85func (s *ClusterHealthService) WaitForGreenStatus() *ClusterHealthService {86 return s.WaitForStatus("green")87}88// WaitForYellowStatus will wait for the "yellow" state.89func (s *ClusterHealthService) WaitForYellowStatus() *ClusterHealthService {90 return s.WaitForStatus("yellow")91}92// Pretty indicates that the JSON response be indented and human readable.93func (s *ClusterHealthService) Pretty(pretty bool) *ClusterHealthService {94 s.pretty = pretty95 return s96}97// buildURL builds the URL for the operation.98func (s *ClusterHealthService) buildURL() (string, url.Values, error) {99 // Build URL100 var err error101 var path string102 if len(s.indices) > 0 {103 path, err = uritemplates.Expand("/_cluster/health/{index}", map[string]string{104 "index": strings.Join(s.indices, ","),105 })106 } else {107 path = "/_cluster/health"108 }109 if err != nil {110 return "", url.Values{}, err111 }112 // Add query string parameters113 params := url.Values{}114 if s.pretty {115 params.Set("pretty", "true")116 }117 if s.level != "" {118 params.Set("level", s.level)119 }120 if s.local != nil {121 params.Set("local", fmt.Sprintf("%v", *s.local))122 }123 if s.masterTimeout != "" {124 params.Set("master_timeout", s.masterTimeout)125 }126 if s.timeout != "" {127 params.Set("timeout", s.timeout)128 }129 if s.waitForActiveShards != nil {130 params.Set("wait_for_active_shards", fmt.Sprintf("%v", s.waitForActiveShards))131 }132 if s.waitForNodes != "" {133 params.Set("wait_for_nodes", s.waitForNodes)134 }135 if s.waitForNoRelocatingShards != nil {136 params.Set("wait_for_no_relocating_shards", fmt.Sprintf("%v", *s.waitForNoRelocatingShards))137 }138 if s.waitForStatus != "" {139 params.Set("wait_for_status", s.waitForStatus)140 }141 return path, params, nil142}143// Validate checks if the operation is valid.144func (s *ClusterHealthService) Validate() error {145 return nil146}147// Do executes the operation.148func (s *ClusterHealthService) Do(ctx context.Context) (*ClusterHealthResponse, error) {149 // Check pre-conditions150 if err := s.Validate(); err != nil {151 return nil, err152 }153 // Get URL for request154 path, params, err := s.buildURL()155 if err != nil {156 return nil, err157 }158 // Get HTTP response159 res, err := s.client.PerformRequest(ctx, PerformRequestOptions{160 Method: "GET",161 Path: path,162 Params: params,163 })164 if err != nil {165 return nil, err166 }167 // Return operation response168 ret := new(ClusterHealthResponse)169 if err := s.client.decoder.Decode(res.Body, ret); err != nil {170 return nil, err171 }172 return ret, nil173}174// ClusterHealthResponse is the response of ClusterHealthService.Do.175type ClusterHealthResponse struct {176 ClusterName string `json:"cluster_name"`177 Status string `json:"status"`178 TimedOut bool `json:"timed_out"`179 NumberOfNodes int `json:"number_of_nodes"`180 NumberOfDataNodes int `json:"number_of_data_nodes"`181 ActivePrimaryShards int `json:"active_primary_shards"`182 ActiveShards int `json:"active_shards"`183 RelocatingShards int `json:"relocating_shards"`184 InitializingShards int `json:"initializing_shards"`185 UnassignedShards int `json:"unassigned_shards"`186 DelayedUnassignedShards int `json:"delayed_unassigned_shards"`187 NumberOfPendingTasks int `json:"number_of_pending_tasks"`188 NumberOfInFlightFetch int `json:"number_of_in_flight_fetch"`189 TaskMaxWaitTimeInQueueInMillis int `json:"task_max_waiting_in_queue_millis"`190 ActiveShardsPercentAsNumber float64 `json:"active_shards_percent_as_number"`191 // Validation failures -> index name -> array of validation failures192 ValidationFailures []map[string][]string `json:"validation_failures"`193 // Index name -> index health194 Indices map[string]*ClusterIndexHealth `json:"indices"`195}196// ClusterIndexHealth will be returned as part of ClusterHealthResponse.197type ClusterIndexHealth struct {198 Status string `json:"status"`199 NumberOfShards int `json:"number_of_shards"`200 NumberOfReplicas int `json:"number_of_replicas"`201 ActivePrimaryShards int `json:"active_primary_shards"`202 ActiveShards int `json:"active_shards"`203 RelocatingShards int `json:"relocating_shards"`...

Full Screen

Full Screen

plugin_test.go

Source:plugin_test.go Github

copy

Full Screen

1package service2import (3 "context"4 "io"5 "io/ioutil"6 "os"7 "path"8 "strings"9 "testing"10 "github.com/docker/docker/api/types"11 "github.com/docker/docker/api/types/filters"12 swarmtypes "github.com/docker/docker/api/types/swarm"13 "github.com/docker/docker/api/types/swarm/runtime"14 "github.com/docker/docker/integration/internal/swarm"15 "github.com/docker/docker/testutil/daemon"16 "github.com/docker/docker/testutil/fixtures/plugin"17 "github.com/docker/docker/testutil/registry"18 "gotest.tools/v3/assert"19 "gotest.tools/v3/poll"20 "gotest.tools/v3/skip"21)22func TestServicePlugin(t *testing.T) {23 skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")24 skip.If(t, testEnv.DaemonInfo.OSType == "windows")25 skip.If(t, os.Getenv("DOCKER_ENGINE_GOARCH") != "amd64")26 defer setupTest(t)()27 reg := registry.NewV2(t)28 defer reg.Close()29 name := "test-" + strings.ToLower(t.Name())30 repo := path.Join(registry.DefaultURL, "swarm", name+":v1")31 repo2 := path.Join(registry.DefaultURL, "swarm", name+":v2")32 d := daemon.New(t)33 d.StartWithBusybox(t)34 apiclient := d.NewClientT(t)35 err := plugin.Create(context.Background(), apiclient, repo)36 assert.NilError(t, err)37 r, err := apiclient.PluginPush(context.Background(), repo, "")38 assert.NilError(t, err)39 _, err = io.Copy(ioutil.Discard, r)40 assert.NilError(t, err)41 err = apiclient.PluginRemove(context.Background(), repo, types.PluginRemoveOptions{})42 assert.NilError(t, err)43 err = plugin.Create(context.Background(), apiclient, repo2)44 assert.NilError(t, err)45 r, err = apiclient.PluginPush(context.Background(), repo2, "")46 assert.NilError(t, err)47 _, err = io.Copy(ioutil.Discard, r)48 assert.NilError(t, err)49 err = apiclient.PluginRemove(context.Background(), repo2, types.PluginRemoveOptions{})50 assert.NilError(t, err)51 d.Stop(t)52 d1 := swarm.NewSwarm(t, testEnv, daemon.WithExperimental())53 defer d1.Stop(t)54 d2 := daemon.New(t, daemon.WithExperimental(), daemon.WithSwarmPort(daemon.DefaultSwarmPort+1))55 d2.StartAndSwarmJoin(t, d1, true)56 defer d2.Stop(t)57 d3 := daemon.New(t, daemon.WithExperimental(), daemon.WithSwarmPort(daemon.DefaultSwarmPort+2))58 d3.StartAndSwarmJoin(t, d1, false)59 defer d3.Stop(t)60 id := d1.CreateService(t, makePlugin(repo, name, nil))61 poll.WaitOn(t, d1.PluginIsRunning(t, name), swarm.ServicePoll)62 poll.WaitOn(t, d2.PluginIsRunning(t, name), swarm.ServicePoll)63 poll.WaitOn(t, d3.PluginIsRunning(t, name), swarm.ServicePoll)64 // test that environment variables are passed from plugin service to plugin instance65 service := d1.GetService(t, id)66 tasks := d1.GetServiceTasks(t, service.Spec.Annotations.Name, filters.Arg("runtime", "plugin"))67 if len(tasks) == 0 {68 t.Log("No tasks found for plugin service")69 t.Fail()70 }71 plugin, _, err := d1.NewClientT(t).PluginInspectWithRaw(context.Background(), name)72 assert.NilError(t, err, "Error inspecting service plugin")73 found := false74 for _, env := range plugin.Settings.Env {75 assert.Equal(t, strings.HasPrefix(env, "baz"), false, "Environment variable entry %q is invalid and should not be present", "baz")76 if strings.HasPrefix(env, "foo=") {77 found = true78 assert.Equal(t, env, "foo=bar")79 }80 }81 assert.Equal(t, true, found, "Environment variable %q not found in plugin", "foo")82 d1.UpdateService(t, service, makePlugin(repo2, name, nil))83 poll.WaitOn(t, d1.PluginReferenceIs(t, name, repo2), swarm.ServicePoll)84 poll.WaitOn(t, d2.PluginReferenceIs(t, name, repo2), swarm.ServicePoll)85 poll.WaitOn(t, d3.PluginReferenceIs(t, name, repo2), swarm.ServicePoll)86 poll.WaitOn(t, d1.PluginIsRunning(t, name), swarm.ServicePoll)87 poll.WaitOn(t, d2.PluginIsRunning(t, name), swarm.ServicePoll)88 poll.WaitOn(t, d3.PluginIsRunning(t, name), swarm.ServicePoll)89 d1.RemoveService(t, id)90 poll.WaitOn(t, d1.PluginIsNotPresent(t, name), swarm.ServicePoll)91 poll.WaitOn(t, d2.PluginIsNotPresent(t, name), swarm.ServicePoll)92 poll.WaitOn(t, d3.PluginIsNotPresent(t, name), swarm.ServicePoll)93 // constrain to managers only94 id = d1.CreateService(t, makePlugin(repo, name, []string{"node.role==manager"}))95 poll.WaitOn(t, d1.PluginIsRunning(t, name), swarm.ServicePoll)96 poll.WaitOn(t, d2.PluginIsRunning(t, name), swarm.ServicePoll)97 poll.WaitOn(t, d3.PluginIsNotPresent(t, name), swarm.ServicePoll)98 d1.RemoveService(t, id)99 poll.WaitOn(t, d1.PluginIsNotPresent(t, name), swarm.ServicePoll)100 poll.WaitOn(t, d2.PluginIsNotPresent(t, name), swarm.ServicePoll)101 poll.WaitOn(t, d3.PluginIsNotPresent(t, name), swarm.ServicePoll)102 // with no name103 id = d1.CreateService(t, makePlugin(repo, "", nil))104 poll.WaitOn(t, d1.PluginIsRunning(t, repo), swarm.ServicePoll)105 poll.WaitOn(t, d2.PluginIsRunning(t, repo), swarm.ServicePoll)106 poll.WaitOn(t, d3.PluginIsRunning(t, repo), swarm.ServicePoll)107 d1.RemoveService(t, id)108 poll.WaitOn(t, d1.PluginIsNotPresent(t, repo), swarm.ServicePoll)109 poll.WaitOn(t, d2.PluginIsNotPresent(t, repo), swarm.ServicePoll)110 poll.WaitOn(t, d3.PluginIsNotPresent(t, repo), swarm.ServicePoll)111}112func makePlugin(repo, name string, constraints []string) func(*swarmtypes.Service) {113 return func(s *swarmtypes.Service) {114 s.Spec.TaskTemplate.Runtime = swarmtypes.RuntimePlugin115 s.Spec.TaskTemplate.PluginSpec = &runtime.PluginSpec{116 Name: name,117 Remote: repo,118 Env: []string{119 "baz", // invalid environment variable entries are ignored120 "foo=bar", // "foo" will be the single environment variable121 },122 }123 if constraints != nil {124 s.Spec.TaskTemplate.Placement = &swarmtypes.Placement{125 Constraints: constraints,126 }127 }128 }129}...

Full Screen

Full Screen

wait

Using AI Code Generation

copy

Full Screen

1import (2type service struct {3}4func (s *service) start() {5 fmt.Printf("Starting %s service...\n", s.name)6 time.Sleep(2 * time.Second)7 fmt.Printf("%s service started!\n", s.name)8}9func (s *service) stop() {10 fmt.Printf("Stopping %s service...\n", s.name)11 time.Sleep(2 * time.Second)12 fmt.Printf("%s service stopped!\n", s.name)13}14func (s *service) restart() {15 fmt.Printf("Restarting %s service...\n", s.name)16 s.stop()17 s.start()18 fmt.Printf("%s service restarted!\n", s.name)19}20func main() {21 s := service{name: "MySQL"}22 s.start()23 s.stop()24 s.restart()25}

Full Screen

Full Screen

wait

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 ch := make(chan int)4 go func() {5 time.Sleep(2 * time.Second)6 fmt.Println("Hello")7 }()8 fmt.Println("Main function")9}

Full Screen

Full Screen

wait

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("main started")4 c := make(chan int)5 go func() {6 fmt.Println("go routine started")7 time.Sleep(5 * time.Second)8 fmt.Println("go routine ended")9 }()10 fmt.Println("main waiting for go routine to finish")11 fmt.Println("main ended")12}

Full Screen

Full Screen

wait

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("main started")4 ch := make(chan int)5 go func() {6 time.Sleep(2 * time.Second)7 fmt.Println("inside goroutine")8 }()9 fmt.Println("before wait")10 fmt.Println("after wait")11 fmt.Println("main stopped")12}

Full Screen

Full Screen

wait

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Main Start")4 c := make(chan string)5 go func() {6 fmt.Println("Go Start")7 time.Sleep(1 * time.Second)8 fmt.Println("Go End")9 }()10 fmt.Println("Main End")11 fmt.Println(<-c)12}

Full Screen

Full Screen

wait

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("main started")4 wait()5 fmt.Println("main ended")6}7func wait() {8 fmt.Println("wait started")9 time.Sleep(2 * time.Second)10 fmt.Println("wait ended")11}

Full Screen

Full Screen

wait

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("main started")4 c := make(chan string)5 go service1(c)6 fmt.Println("main waiting for service to complete")7 fmt.Println(<-c)8 fmt.Println("main completed")9}10func service1(c chan string) {11 fmt.Println("service1 started")12 time.Sleep(1 * time.Second)13 fmt.Println("service1 completed")14}

Full Screen

Full Screen

wait

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 s := new(Service)4 s.Start()5 s.Wait()6 fmt.Println(s)7}8type Service struct {9}10func (s *Service) Start() {11}12func (s *Service) Wait() {13 for {14 if s.isRunning {15 fmt.Println("Service is running")16 time.Sleep(time.Second)17 } else {18 fmt.Println("Service is stopped")19 time.Sleep(time.Second)20 }21 }22}

Full Screen

Full Screen

wait

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("main() started")4 s := new(service)5 s.wait()6 fmt.Println("main() stopped")7}8type service struct {9}10func (s *service) wait() {11 fmt.Println("wait() started")12 ch := make(chan string)13 go func() {14 fmt.Println("go func() started")15 fmt.Println("go func() stopped")16 }()17 fmt.Println(msg)18 fmt.Println("wait() stopped")19}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful