-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: change services to be headless
- Loading branch information
1 parent
339f749
commit a7f3913
Showing
5 changed files
with
93 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package basic | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
const gopingImage = "ghcr.io/celestiaorg/goping:4803195" | ||
|
||
func (s *Suite) TestHeadlessService() { | ||
const ( | ||
namePrefix = "headless-srv-test" | ||
numOfPingPackets = 100 | ||
numOfTests = 10 | ||
packetTimeout = 1 * time.Second | ||
gopingPort = 8001 | ||
) | ||
ctx := context.Background() | ||
|
||
mother, err := s.Knuu.NewInstance(namePrefix + "mother") | ||
s.Require().NoError(err) | ||
|
||
err = mother.Build().SetImage(ctx, gopingImage) | ||
s.Require().NoError(err) | ||
|
||
s.Require().NoError(mother.Network().AddPortTCP(gopingPort)) | ||
s.Require().NoError(mother.Build().Commit(ctx)) | ||
|
||
err = mother.Build().SetEnvironmentVariable("SERVE_ADDR", fmt.Sprintf("0.0.0.0:%d", gopingPort)) | ||
s.Require().NoError(err) | ||
|
||
target, err := mother.CloneWithName(namePrefix + "target") | ||
s.Require().NoError(err) | ||
|
||
executor, err := mother.CloneWithName(namePrefix + "executor") | ||
s.Require().NoError(err) | ||
|
||
// Prepare ping executor & target | ||
|
||
s.Require().NoError(target.Execution().Start(ctx)) | ||
s.Require().NoError(executor.Execution().Start(ctx)) | ||
|
||
targetEndpoint, err := target.Network().GetServiceEndpoint(gopingPort) | ||
s.Require().NoError(err) | ||
s.T().Logf("targetEndpoint: %v", targetEndpoint) | ||
|
||
s.T().Log("Starting ping test. It takes a while.") | ||
for i := 0; i < numOfTests; i++ { | ||
startTime := time.Now() | ||
|
||
output, err := executor.Execution().ExecuteCommand(ctx, "goping", "ping", "-q", | ||
"-c", fmt.Sprint(numOfPingPackets), | ||
"-t", packetTimeout.String(), | ||
"-m", "packetloss", | ||
targetEndpoint) | ||
s.Require().NoError(err) | ||
|
||
elapsed := time.Since(startTime) | ||
s.T().Logf("i: %d, test took %d seconds, output: `%s`", i, int64(elapsed.Seconds()), output) | ||
|
||
gotPacketloss, err := strconv.ParseFloat(output, 64) | ||
s.Require().NoError(err, fmt.Sprintf("error parsing output: `%s`", output)) | ||
|
||
s.Assert().Zero(gotPacketloss) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters