TestUpdateLimitsReservations tests that limits and reservations are updated, and that values are not updated are not reset to their default value
(t *testing.T)
| 660 | // TestUpdateLimitsReservations tests that limits and reservations are updated, |
| 661 | // and that values are not updated are not reset to their default value |
| 662 | func TestUpdateLimitsReservations(t *testing.T) { |
| 663 | // test that updating works if the service did not previously |
| 664 | // have limits set (https://github.com/moby/moby/issues/38363) |
| 665 | t.Run("update limits from scratch", func(t *testing.T) { |
| 666 | spec := swarm.ServiceSpec{ |
| 667 | TaskTemplate: swarm.TaskSpec{ |
| 668 | ContainerSpec: &swarm.ContainerSpec{}, |
| 669 | }, |
| 670 | } |
| 671 | flags := newUpdateCommand(nil).Flags() |
| 672 | err := flags.Set(flagLimitCPU, "2") |
| 673 | assert.NilError(t, err) |
| 674 | err = flags.Set(flagLimitMemory, "200M") |
| 675 | assert.NilError(t, err) |
| 676 | err = flags.Set(flagLimitPids, "100") |
| 677 | assert.NilError(t, err) |
| 678 | err = updateService(context.Background(), nil, flags, &spec) |
| 679 | assert.NilError(t, err) |
| 680 | assert.Check(t, is.Equal(spec.TaskTemplate.Resources.Limits.NanoCPUs, int64(2000000000))) |
| 681 | assert.Check(t, is.Equal(spec.TaskTemplate.Resources.Limits.MemoryBytes, int64(209715200))) |
| 682 | assert.Check(t, is.Equal(spec.TaskTemplate.Resources.Limits.Pids, int64(100))) |
| 683 | }) |
| 684 | |
| 685 | // test that updating works if the service did not previously |
| 686 | // have reservations set (https://github.com/moby/moby/issues/38363) |
| 687 | t.Run("update reservations from scratch", func(t *testing.T) { |
| 688 | spec := swarm.ServiceSpec{ |
| 689 | TaskTemplate: swarm.TaskSpec{ |
| 690 | ContainerSpec: &swarm.ContainerSpec{}, |
| 691 | }, |
| 692 | } |
| 693 | flags := newUpdateCommand(nil).Flags() |
| 694 | err := flags.Set(flagReserveCPU, "2") |
| 695 | assert.NilError(t, err) |
| 696 | err = flags.Set(flagReserveMemory, "200M") |
| 697 | assert.NilError(t, err) |
| 698 | err = updateService(context.Background(), nil, flags, &spec) |
| 699 | assert.NilError(t, err) |
| 700 | }) |
| 701 | |
| 702 | spec := swarm.ServiceSpec{ |
| 703 | TaskTemplate: swarm.TaskSpec{ |
| 704 | ContainerSpec: &swarm.ContainerSpec{}, |
| 705 | Resources: &swarm.ResourceRequirements{ |
| 706 | Limits: &swarm.Limit{ |
| 707 | NanoCPUs: 1000000000, |
| 708 | MemoryBytes: 104857600, |
| 709 | Pids: 100, |
| 710 | }, |
| 711 | Reservations: &swarm.Resources{ |
| 712 | NanoCPUs: 1000000000, |
| 713 | MemoryBytes: 104857600, |
| 714 | }, |
| 715 | }, |
| 716 | }, |
| 717 | } |
| 718 | |
| 719 | // Updating without flags set should not modify existing values |
nothing calls this directly
no test coverage detected
searching dependent graphs…