Skip to content

[TT-6011] Fix non-functional coprocess apis, add tests#4055

Merged
titpetric merged 5 commits into
masterfrom
fix/coprocess-tests-and-code-coverage
Mar 22, 2024
Merged

[TT-6011] Fix non-functional coprocess apis, add tests#4055
titpetric merged 5 commits into
masterfrom
fix/coprocess-tests-and-code-coverage

Conversation

@titpetric

@titpetric titpetric commented May 17, 2022

Copy link
Copy Markdown
Contributor

Description

This PR adds test for the coprocess StoreData and GetData apis. It fixes an issue with the redis connection and updates use to latest storage package changes.

https://tyktech.atlassian.net/browse/TT-6011

Motivation and Context

Coprocess APIs don't connect to redis, don't have timeouts. I fixed opening the Redis connection, added unit tests to verify functionality and add code coverage.

How This Has Been Tested

$ TYK_LOGLEVEL=debug go test -run=TestCoprocess -v .
[May 17 13:54:52] DEBUG Using serializer protobuf for analytics 

=== RUN   TestCoprocessAPIs
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
--- PASS: TestCoprocessAPIs (0.02s)
=== RUN   TestCoprocessLog
time="May 17 13:54:52" level=debug msg="test logging message 0" prefix=python
time="May 17 13:54:52" level=error msg="test logging message 1" prefix=python
time="May 17 13:54:52" level=warning msg="test logging message 2" prefix=python
time="May 17 13:54:52" level=info msg="test logging message 3" prefix=python
--- PASS: TestCoprocessLog (0.00s)
=== RUN   TestCoprocessSystemEvent
--- PASS: TestCoprocessSystemEvent (0.00s)
PASS
ok  	github.com/TykTechnologies/tyk/gateway	0.048s

Before? No tests.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring or add test (improvements in base code or adds test coverage to functionality)

Checklist

  • Make sure you are requesting to pull a topic/feature/bugfix branch (right side). If pulling from your own
    fork, don't request your master!
  • Make sure you are making a pull request against the master branch (left side). Also, you should start
    your branch off our latest master.
  • My change requires a change to the documentation.
    • If you've changed APIs, describe what needs to be updated in the documentation.
    • If new config option added, ensure that it can be set via ENV variable
  • I have updated the documentation accordingly.
  • Modules and vendor dependencies have been updated; run go mod tidy && go mod vendor
  • When updating library version must provide reason/explanation for this update.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • Check your code additions will not fail linting checks:
    • go fmt -s
    • go vet

Final note for review

These functions need to access the gateway config (e.g. load it). Currently, I'm only passing &config.Config{} to use defaults, which works for tests but won't work on a custom-configured gateway instance. Need to get the actual config. How? ;)

@Tyk-ITS

Tyk-ITS commented May 17, 2022

Copy link
Copy Markdown
Contributor

API tests result: skipped 🚫
Branch used: refs/pull/4055/merge
Commit:
Triggered by: pull_request (@titpetric)
Execution page

2 similar comments
@Tyk-ITS

Tyk-ITS commented May 17, 2022

Copy link
Copy Markdown
Contributor

API tests result: skipped 🚫
Branch used: refs/pull/4055/merge
Commit:
Triggered by: pull_request (@titpetric)
Execution page

@Tyk-ITS

Tyk-ITS commented May 17, 2022

Copy link
Copy Markdown
Contributor

API tests result: skipped 🚫
Branch used: refs/pull/4055/merge
Commit:
Triggered by: pull_request (@titpetric)
Execution page

@TykTechnologies TykTechnologies deleted a comment from github-actions Bot May 17, 2022
@Tyk-ITS

Tyk-ITS commented May 18, 2022

Copy link
Copy Markdown
Contributor

API tests result: failure 🚫
Branch used: refs/pull/4055/merge
Commit:
Triggered by: pull_request (@titpetric)
Execution page

@Tyk-ITS

Tyk-ITS commented May 18, 2022

Copy link
Copy Markdown
Contributor

API tests result: success
Branch used: refs/pull/4055/merge
Commit:
Triggered by: pull_request (@titpetric)
Execution page

@titpetric
titpetric marked this pull request as ready for review May 18, 2022 14:26
@titpetric
titpetric force-pushed the fix/coprocess-tests-and-code-coverage branch from 356798e to c810f4a Compare May 18, 2022 14:27
@sonarqubecloud

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

94.1% 94.1% Coverage
0.0% 0.0% Duplication

@Tyk-ITS

Tyk-ITS commented May 18, 2022

Copy link
Copy Markdown
Contributor

API tests result: success
Branch used: refs/pull/4055/merge
Commit: c810f4a
Triggered by: pull_request (@titpetric)
Execution page

Comment thread gateway/coprocess_api.go
@titpetric titpetric changed the title Fix non-functional coprocess apis, add tests [TT-5498] Fix non-functional coprocess apis, add tests Jun 9, 2022
@titpetric

Copy link
Copy Markdown
Contributor Author

@matiasinsaurralde hey, would you be so kind to review. I added the test cases for the coprocess bindings, and fixed a flaky test in the process (race condition when connecting to redis). It also fixes a leak of the redis connection with a ctx cancellation.

If this isn't in use, I'd be happy to delete this

@titpetric

Copy link
Copy Markdown
Contributor Author

cc @ermirizio @buger I'm asuming the referenced PR above is going to be orphaned and/or somebody needs to pick up this. I am/was happy with my proposed diff here, but we can look to merge the two PR improvements. I'm fine picking this up if there isn't something in the works already

@ermirizio

Copy link
Copy Markdown
Collaborator

@titpetric I'm afraid I can't audit the code this time since is not within my expertise, I'm more like an stakeholder for this since we'll need this and the referenced PR to get our plugin for OIDC to work. https://tyktech.atlassian.net/browse/TD-1088 . It'll be great if you could take this so we get unblocked :)

@lghiur

lghiur commented Nov 17, 2022

Copy link
Copy Markdown
Collaborator

@titpetric is this still needed?

@titpetric
titpetric force-pushed the fix/coprocess-tests-and-code-coverage branch from c810f4a to c91ef40 Compare March 22, 2024 08:18
@github-actions

Copy link
Copy Markdown
Contributor

API Changes

no api changes detected

@github-actions

Copy link
Copy Markdown
Contributor

💥 CI tests failed 🙈

git-state

all ok

Please look at the run or in the Checks tab.

@github-actions

Copy link
Copy Markdown
Contributor

💥 CI tests failed 🙈

git-state

all ok

Please look at the run or in the Checks tab.

@github-actions

Copy link
Copy Markdown
Contributor

💥 CI tests failed 🙈

git-state

all ok

Please look at the run or in the Checks tab.

@sonarqubecloud

Copy link
Copy Markdown

@titpetric titpetric changed the title [TT-5498] Fix non-functional coprocess apis, add tests [TT-6011] Fix non-functional coprocess apis, add tests Mar 22, 2024
@titpetric
titpetric merged commit 9cb8304 into master Mar 22, 2024
@titpetric
titpetric deleted the fix/coprocess-tests-and-code-coverage branch March 22, 2024 10:37
@titpetric

Copy link
Copy Markdown
Contributor Author

/release to release-5.3

@tykbot

tykbot Bot commented Mar 22, 2024

Copy link
Copy Markdown

Working on it! Note that it can take a few minutes.

tykbot Bot pushed a commit that referenced this pull request Mar 22, 2024
## Description

This PR adds test for the coprocess StoreData and GetData apis. It fixes
an issue with the redis connection and updates use to latest storage
package changes.

https://tyktech.atlassian.net/browse/TT-6011

## Motivation and Context

Coprocess APIs don't connect to redis, don't have timeouts. I fixed
opening the Redis connection, added unit tests to verify functionality
and add code coverage.

## How This Has Been Tested

```
$ TYK_LOGLEVEL=debug go test -run=TestCoprocess -v .
[May 17 13:54:52] DEBUG Using serializer protobuf for analytics 

=== RUN   TestCoprocessAPIs
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
--- PASS: TestCoprocessAPIs (0.02s)
=== RUN   TestCoprocessLog
time="May 17 13:54:52" level=debug msg="test logging message 0" prefix=python
time="May 17 13:54:52" level=error msg="test logging message 1" prefix=python
time="May 17 13:54:52" level=warning msg="test logging message 2" prefix=python
time="May 17 13:54:52" level=info msg="test logging message 3" prefix=python
--- PASS: TestCoprocessLog (0.00s)
=== RUN   TestCoprocessSystemEvent
--- PASS: TestCoprocessSystemEvent (0.00s)
PASS
ok  	github.com/TykTechnologies/tyk/gateway	0.048s
```

Before? No tests.

## Types of changes
<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [x] Refactoring or add test (improvements in base code or adds test
coverage to functionality)

## Checklist
<!-- Go over all the following points, and put an `x` in all the boxes
that apply -->
<!-- If you're unsure about any of these, don't hesitate to ask; we're
here to help! -->
- [ ] Make sure you are requesting to **pull a topic/feature/bugfix
branch** (right side). If pulling from your own
      fork, don't request your `master`!
- [ ] Make sure you are making a pull request against the **`master`
branch** (left side). Also, you should start
      *your branch* off *our latest `master`*.
- [ ] My change requires a change to the documentation.
- [ ] If you've changed APIs, describe what needs to be updated in the
documentation.
- [ ] If new config option added, ensure that it can be set via ENV
variable
- [ ] I have updated the documentation accordingly.
- [ ] Modules and vendor dependencies have been updated; run `go mod
tidy && go mod vendor`
- [ ] When updating library version must provide reason/explanation for
this update.
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.
- [ ] Check your code additions will not fail linting checks:
  - [ ] `go fmt -s`
  - [ ] `go vet`

## Final note for review

These functions need to access the gateway config (e.g. load it).
Currently, I'm only passing `&config.Config{}` to use defaults, which
works for tests but won't work on a custom-configured gateway instance.
Need to get the actual config. How? ;)

---------

Co-authored-by: Tit Petric <[email protected]>

(cherry picked from commit 9cb8304)
@tykbot

tykbot Bot commented Mar 22, 2024

Copy link
Copy Markdown

@titpetric Succesfully merged PR

buger added a commit that referenced this pull request Mar 22, 2024
…add tests (#4055)

[TT-6011] Fix non-functional coprocess apis, add tests (#4055)

## Description

This PR adds test for the coprocess StoreData and GetData apis. It fixes
an issue with the redis connection and updates use to latest storage
package changes.

https://tyktech.atlassian.net/browse/TT-6011

## Motivation and Context

Coprocess APIs don't connect to redis, don't have timeouts. I fixed
opening the Redis connection, added unit tests to verify functionality
and add code coverage.

## How This Has Been Tested

```
$ TYK_LOGLEVEL=debug go test -run=TestCoprocess -v .
[May 17 13:54:52] DEBUG Using serializer protobuf for analytics 

=== RUN   TestCoprocessAPIs
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
--- PASS: TestCoprocessAPIs (0.02s)
=== RUN   TestCoprocessLog
time="May 17 13:54:52" level=debug msg="test logging message 0" prefix=python
time="May 17 13:54:52" level=error msg="test logging message 1" prefix=python
time="May 17 13:54:52" level=warning msg="test logging message 2" prefix=python
time="May 17 13:54:52" level=info msg="test logging message 3" prefix=python
--- PASS: TestCoprocessLog (0.00s)
=== RUN   TestCoprocessSystemEvent
--- PASS: TestCoprocessSystemEvent (0.00s)
PASS
ok  	github.com/TykTechnologies/tyk/gateway	0.048s
```

Before? No tests.

## Types of changes
<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [x] Refactoring or add test (improvements in base code or adds test
coverage to functionality)

## Checklist
<!-- Go over all the following points, and put an `x` in all the boxes
that apply -->
<!-- If you're unsure about any of these, don't hesitate to ask; we're
here to help! -->
- [ ] Make sure you are requesting to **pull a topic/feature/bugfix
branch** (right side). If pulling from your own
      fork, don't request your `master`!
- [ ] Make sure you are making a pull request against the **`master`
branch** (left side). Also, you should start
      *your branch* off *our latest `master`*.
- [ ] My change requires a change to the documentation.
- [ ] If you've changed APIs, describe what needs to be updated in the
documentation.
- [ ] If new config option added, ensure that it can be set via ENV
variable
- [ ] I have updated the documentation accordingly.
- [ ] Modules and vendor dependencies have been updated; run `go mod
tidy && go mod vendor`
- [ ] When updating library version must provide reason/explanation for
this update.
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.
- [ ] Check your code additions will not fail linting checks:
  - [ ] `go fmt -s`
  - [ ] `go vet`

## Final note for review

These functions need to access the gateway config (e.g. load it).
Currently, I'm only passing `&config.Config{}` to use defaults, which
works for tests but won't work on a custom-configured gateway instance.
Need to get the actual config. How? ;)

---------

Co-authored-by: Tit Petric <[email protected]>
@titpetric

Copy link
Copy Markdown
Contributor Author

/release to release-5-lts

@tykbot

tykbot Bot commented Mar 22, 2024

Copy link
Copy Markdown

Working on it! Note that it can take a few minutes.

tykbot Bot pushed a commit that referenced this pull request Mar 22, 2024
This PR adds test for the coprocess StoreData and GetData apis. It fixes
an issue with the redis connection and updates use to latest storage
package changes.

https://tyktech.atlassian.net/browse/TT-6011

Coprocess APIs don't connect to redis, don't have timeouts. I fixed
opening the Redis connection, added unit tests to verify functionality
and add code coverage.

```
$ TYK_LOGLEVEL=debug go test -run=TestCoprocess -v .
[May 17 13:54:52] DEBUG Using serializer protobuf for analytics

=== RUN   TestCoprocessAPIs
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
--- PASS: TestCoprocessAPIs (0.02s)
=== RUN   TestCoprocessLog
time="May 17 13:54:52" level=debug msg="test logging message 0" prefix=python
time="May 17 13:54:52" level=error msg="test logging message 1" prefix=python
time="May 17 13:54:52" level=warning msg="test logging message 2" prefix=python
time="May 17 13:54:52" level=info msg="test logging message 3" prefix=python
--- PASS: TestCoprocessLog (0.00s)
=== RUN   TestCoprocessSystemEvent
--- PASS: TestCoprocessSystemEvent (0.00s)
PASS
ok  	github.com/TykTechnologies/tyk/gateway	0.048s
```

Before? No tests.

<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [x] Refactoring or add test (improvements in base code or adds test
coverage to functionality)

<!-- Go over all the following points, and put an `x` in all the boxes
that apply -->
<!-- If you're unsure about any of these, don't hesitate to ask; we're
here to help! -->
- [ ] Make sure you are requesting to **pull a topic/feature/bugfix
branch** (right side). If pulling from your own
      fork, don't request your `master`!
- [ ] Make sure you are making a pull request against the **`master`
branch** (left side). Also, you should start
      *your branch* off *our latest `master`*.
- [ ] My change requires a change to the documentation.
- [ ] If you've changed APIs, describe what needs to be updated in the
documentation.
- [ ] If new config option added, ensure that it can be set via ENV
variable
- [ ] I have updated the documentation accordingly.
- [ ] Modules and vendor dependencies have been updated; run `go mod
tidy && go mod vendor`
- [ ] When updating library version must provide reason/explanation for
this update.
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.
- [ ] Check your code additions will not fail linting checks:
  - [ ] `go fmt -s`
  - [ ] `go vet`

These functions need to access the gateway config (e.g. load it).
Currently, I'm only passing `&config.Config{}` to use defaults, which
works for tests but won't work on a custom-configured gateway instance.
Need to get the actual config. How? ;)

---------

Co-authored-by: Tit Petric <[email protected]>

(cherry picked from commit 9cb8304)
@tykbot

tykbot Bot commented Mar 22, 2024

Copy link
Copy Markdown

@titpetric Succesfully merged PR

titpetric pushed a commit that referenced this pull request Mar 23, 2024
This PR adds test for the coprocess StoreData and GetData apis. It fixes
an issue with the redis connection and updates use to latest storage
package changes.

https://tyktech.atlassian.net/browse/TT-6011

Coprocess APIs don't connect to redis, don't have timeouts. I fixed
opening the Redis connection, added unit tests to verify functionality
and add code coverage.

```
$ TYK_LOGLEVEL=debug go test -run=TestCoprocess -v .
[May 17 13:54:52] DEBUG Using serializer protobuf for analytics

=== RUN   TestCoprocessAPIs
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
--- PASS: TestCoprocessAPIs (0.02s)
=== RUN   TestCoprocessLog
time="May 17 13:54:52" level=debug msg="test logging message 0" prefix=python
time="May 17 13:54:52" level=error msg="test logging message 1" prefix=python
time="May 17 13:54:52" level=warning msg="test logging message 2" prefix=python
time="May 17 13:54:52" level=info msg="test logging message 3" prefix=python
--- PASS: TestCoprocessLog (0.00s)
=== RUN   TestCoprocessSystemEvent
--- PASS: TestCoprocessSystemEvent (0.00s)
PASS
ok  	github.com/TykTechnologies/tyk/gateway	0.048s
```

Before? No tests.

<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [x] Refactoring or add test (improvements in base code or adds test
coverage to functionality)

<!-- Go over all the following points, and put an `x` in all the boxes
that apply -->
<!-- If you're unsure about any of these, don't hesitate to ask; we're
here to help! -->
- [ ] Make sure you are requesting to **pull a topic/feature/bugfix
branch** (right side). If pulling from your own
      fork, don't request your `master`!
- [ ] Make sure you are making a pull request against the **`master`
branch** (left side). Also, you should start
      *your branch* off *our latest `master`*.
- [ ] My change requires a change to the documentation.
- [ ] If you've changed APIs, describe what needs to be updated in the
documentation.
- [ ] If new config option added, ensure that it can be set via ENV
variable
- [ ] I have updated the documentation accordingly.
- [ ] Modules and vendor dependencies have been updated; run `go mod
tidy && go mod vendor`
- [ ] When updating library version must provide reason/explanation for
this update.
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.
- [ ] Check your code additions will not fail linting checks:
  - [ ] `go fmt -s`
  - [ ] `go vet`

These functions need to access the gateway config (e.g. load it).
Currently, I'm only passing `&config.Config{}` to use defaults, which
works for tests but won't work on a custom-configured gateway instance.
Need to get the actual config. How? ;)

---------

Co-authored-by: Tit Petric <[email protected]>

(cherry picked from commit 9cb8304)
titpetric pushed a commit that referenced this pull request Mar 23, 2024
…, add tests (#4055) (#6179)

[TT-6011] Fix non-functional coprocess apis, add tests (#4055)

## Description

This PR adds test for the coprocess StoreData and GetData apis. It fixes
an issue with the redis connection and updates use to latest storage
package changes.

https://tyktech.atlassian.net/browse/TT-6011

## Motivation and Context

Coprocess APIs don't connect to redis, don't have timeouts. I fixed
opening the Redis connection, added unit tests to verify functionality
and add code coverage.

## How This Has Been Tested

```
$ TYK_LOGLEVEL=debug go test -run=TestCoprocess -v .
[May 17 13:54:52] DEBUG Using serializer protobuf for analytics 

=== RUN   TestCoprocessAPIs
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
time="May 17 13:54:52" level=debug msg="Creating new Redis connection pool"
time="May 17 13:54:52" level=info msg="--> [REDIS] Creating single-node client"
--- PASS: TestCoprocessAPIs (0.02s)
=== RUN   TestCoprocessLog
time="May 17 13:54:52" level=debug msg="test logging message 0" prefix=python
time="May 17 13:54:52" level=error msg="test logging message 1" prefix=python
time="May 17 13:54:52" level=warning msg="test logging message 2" prefix=python
time="May 17 13:54:52" level=info msg="test logging message 3" prefix=python
--- PASS: TestCoprocessLog (0.00s)
=== RUN   TestCoprocessSystemEvent
--- PASS: TestCoprocessSystemEvent (0.00s)
PASS
ok  	github.com/TykTechnologies/tyk/gateway	0.048s
```

Before? No tests.

## Types of changes
<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [x] Refactoring or add test (improvements in base code or adds test
coverage to functionality)

## Checklist
<!-- Go over all the following points, and put an `x` in all the boxes
that apply -->
<!-- If you're unsure about any of these, don't hesitate to ask; we're
here to help! -->
- [ ] Make sure you are requesting to **pull a topic/feature/bugfix
branch** (right side). If pulling from your own
      fork, don't request your `master`!
- [ ] Make sure you are making a pull request against the **`master`
branch** (left side). Also, you should start
      *your branch* off *our latest `master`*.
- [ ] My change requires a change to the documentation.
- [ ] If you've changed APIs, describe what needs to be updated in the
documentation.
- [ ] If new config option added, ensure that it can be set via ENV
variable
- [ ] I have updated the documentation accordingly.
- [ ] Modules and vendor dependencies have been updated; run `go mod
tidy && go mod vendor`
- [ ] When updating library version must provide reason/explanation for
this update.
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.
- [ ] Check your code additions will not fail linting checks:
  - [ ] `go fmt -s`
  - [ ] `go vet`

## Final note for review

These functions need to access the gateway config (e.g. load it).
Currently, I'm only passing `&config.Config{}` to use defaults, which
works for tests but won't work on a custom-configured gateway instance.
Need to get the actual config. How? ;)

---------

Co-authored-by: Tit Petric <[email protected]>

[TT-6011]:
https://tyktech.atlassian.net/browse/TT-6011?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

---------

Co-authored-by: Tit Petric <[email protected]>
Co-authored-by: Tit Petric <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants