forked from chaos-mesh/chaos-mesh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(time chaos): timechaos not injected to the child process (chaos-m…
…esh#3725) * fix(time chaos): timechaos not injected to the child process Signed-off-by: STRRL <[email protected]> * chore: update CHANGELOG Signed-off-by: STRRL <[email protected]> * test(e2e): testcases for inject timechaos for child process Signed-off-by: STRRL <[email protected]> Signed-off-by: STRRL <[email protected]> Co-authored-by: Ti Chi Robot <[email protected]>
- Loading branch information
1 parent
99c6581
commit f45d612
Showing
8 changed files
with
189 additions
and
13 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2021 Chaos Mesh Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"io/ioutil" | ||
"net/http" | ||
"os" | ||
"os/exec" | ||
"time" | ||
) | ||
|
||
type childProcessTimeServer interface { | ||
Start(ctx context.Context) error | ||
Time() (*time.Time, error) | ||
} | ||
|
||
var _ childProcessTimeServer = (*defaultChildProcessTimeServer)(nil) | ||
|
||
// the default implementation would create another instance of e2e-helper, but bind with a different port | ||
type defaultChildProcessTimeServer struct { | ||
} | ||
|
||
// Start implements childProcessTimeServer | ||
func (s *defaultChildProcessTimeServer) Start(ctx context.Context) error { | ||
selfPath, err := os.Executable() | ||
if err != nil { | ||
return err | ||
} | ||
return exec.CommandContext(ctx, selfPath, "--port", "8081").Run() | ||
} | ||
|
||
// Time implements childProcessTimeServer | ||
func (s *defaultChildProcessTimeServer) Time() (*time.Time, error) { | ||
resp, err := http.Get("http://localhost:8081/time") | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer resp.Body.Close() | ||
bytes, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
time, err := time.Parse(time.RFC3339Nano, string(bytes)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &time, nil | ||
} |
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
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