TestReconcileContainers_DependsOnScaleDown verifies that scale-down of a service still propagates through serviceNodes, so a dependent service waits for the scale-down's RemoveContainer to finish before starting its own ops.
(t *testing.T)
| 622 | // service still propagates through serviceNodes, so a dependent service waits |
| 623 | // for the scale-down's RemoveContainer to finish before starting its own ops. |
| 624 | func TestReconcileContainers_DependsOnScaleDown(t *testing.T) { |
| 625 | svc := types.ServiceConfig{Name: "db", Scale: intPtr(0)} |
| 626 | hash := mustServiceHash(t, svc) |
| 627 | |
| 628 | project := &types.Project{ |
| 629 | Name: "myproject", |
| 630 | Services: types.Services{ |
| 631 | "db": svc, |
| 632 | "web": { |
| 633 | Name: "web", |
| 634 | Scale: intPtr(1), |
| 635 | DependsOn: types.DependsOnConfig{ |
| 636 | "db": {Condition: types.ServiceConditionStarted}, |
| 637 | }, |
| 638 | }, |
| 639 | }, |
| 640 | } |
| 641 | observed := &ObservedState{ |
| 642 | ProjectName: "myproject", |
| 643 | Containers: map[string][]ObservedContainer{ |
| 644 | "db": {{ |
| 645 | ID: "c1", Number: 1, State: container.StateRunning, ConfigHash: hash, |
| 646 | Summary: container.Summary{ |
| 647 | ID: "c1", State: container.StateRunning, |
| 648 | Labels: map[string]string{api.ServiceLabel: "db", api.ContainerNumberLabel: "1", api.ConfigHashLabel: hash}, |
| 649 | }, |
| 650 | }}, |
| 651 | }, |
| 652 | Networks: map[string]ObservedNetwork{}, |
| 653 | Volumes: map[string]ObservedVolume{}, |
| 654 | } |
| 655 | |
| 656 | plan, err := reconcile(t.Context(), project, observed, defaultReconcileOptions(), noPrompt) |
| 657 | assert.NilError(t, err) |
| 658 | |
| 659 | // db scales 1→0: Stop+Remove. web's CreateContainer must depend on the |
| 660 | // Remove (#2), proving serviceNodes is updated even when only scale-down |
| 661 | // happens for the dependency. |
| 662 | assert.Equal(t, plan.String(), strings.TrimSpace(` |
| 663 | [] -> #1 service:db:1, StopContainer, scale down |
| 664 | [1] -> #2 service:db:1, RemoveContainer, scale down |
| 665 | [2] -> #3 service:web:1, CreateContainer, no existing container |
| 666 | `)+"\n") |
| 667 | } |
| 668 | |
| 669 | func TestReconcileOrphans(t *testing.T) { |
| 670 | project := &types.Project{ |
nothing calls this directly
no test coverage detected