MCPcopy
hub / github.com/moby/moby / TestCreateServiceMemorySwap

Function TestCreateServiceMemorySwap

integration/service/create_test.go:469–566  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

467}
468
469func TestCreateServiceMemorySwap(t *testing.T) {
470 ctx := setupTest(t)
471 d := swarm.NewSwarm(ctx, t, testEnv)
472 defer d.Stop(t)
473 apiClient := d.NewClientT(t)
474
475 toPtr := func(v int64) *int64 { return &v }
476 tests := []struct {
477 testName string
478
479 swapSpec *int64
480 limitSpec int64
481
482 // as reported by Docker
483 expectedDockerSwap int64
484 }{
485 {
486 testName: "default",
487 },
488 {
489 testName: "memory-limit and memory-swap",
490 swapSpec: toPtr(1 * units.MiB),
491 limitSpec: 20 * units.MiB,
492 expectedDockerSwap: 21 * units.MiB,
493 },
494 {
495 testName: "memory-limit alone - should default to twice as much swap",
496 limitSpec: 20 * units.MiB,
497 expectedDockerSwap: 40 * units.MiB,
498 },
499 {
500 testName: "memory-limit and zero memory-swap",
501 swapSpec: toPtr(0),
502 limitSpec: 20 * units.MiB,
503 expectedDockerSwap: 20 * units.MiB,
504 },
505 {
506 testName: "memory-limit and unlimited memory-swap",
507 swapSpec: toPtr(-1),
508 limitSpec: 20 * units.MiB,
509 expectedDockerSwap: -1,
510 },
511 }
512
513 for _, testCase := range tests {
514 t.Run("service create with "+testCase.testName, func(t *testing.T) {
515 serviceID := swarm.CreateService(
516 ctx, t, d,
517 swarm.ServiceWithMemorySwap(testCase.swapSpec, testCase.limitSpec),
518 )
519 poll.WaitOn(t, swarm.RunningTasksCount(ctx, apiClient, serviceID, 1))
520
521 inspect, err := apiClient.ServiceInspect(ctx, serviceID, client.ServiceInspectOptions{})
522 assert.NilError(t, err)
523
524 filter := make(client.Filters)
525 filter.Add("service", serviceID)
526 tasks, err := apiClient.TaskList(ctx, client.TaskListOptions{

Callers

nothing calls this directly

Calls 15

NewSwarmFunction · 0.92
CreateServiceFunction · 0.92
ServiceWithMemorySwapFunction · 0.92
RunningTasksCountFunction · 0.92
CreateServiceSpecFunction · 0.92
NewClientTMethod · 0.80
CheckMethod · 0.80
EqualMethod · 0.80
setupTestFunction · 0.70
RunMethod · 0.65
ServiceInspectMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…