Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 2 Redis instances/containers on GitHub Actions #1188

Open
crynobone opened this issue Sep 3, 2020 · 3 comments
Open

Add 2 Redis instances/containers on GitHub Actions #1188

crynobone opened this issue Sep 3, 2020 · 3 comments

Comments

@crynobone
Copy link
Contributor

At the moment we are only properly testing RedisCache and RedisStorage using Travis-CI. It would be nice if we can have the same test running on GitHub Actions with the following requirements:

  • Run redis on host port 6379 without password.
  • Run redis on host port 6379 with password secret.
@crynobone crynobone changed the title Add 2 Redis instance/container on GitHub Actions Add 2 Redis instances/containers on GitHub Actions Sep 3, 2020
@zaherg
Copy link
Contributor

zaherg commented Sep 3, 2020

Based on my tests I found out that the tests will fail and return connection refused even on my local environment (PHP 7.4.9) while connecting to redis locally, notice the has test which does not require an authentication.

image

and this is the same thing I have found on github actions.

now to run the tests with/without passwords we should split the redis group into two groups one with validation and the second without a validation, or we can create an ENV var and add it to test function like

    protected function isSecure()
    {
        return $_ENV['SECURE'];
    }

    /** @test */
    public function valid_auth()
    {
        if(!$this->isSecure()) {
            $this->markTestSkipped('This test needs a secure instance of redis');
        }
        
        $storage = new RedisStorage($this->getRedisHost(), $this->getAuthRedisPort(), 'secret');
        $key = 'key';
        $data = ['foo' => 1, 'bar' => new \DateTime()];
        $storage->save($data, $key);
        self::assertEquals(Collection::make($data), $storage->get($key));
    }

    public function get()
    {
        
        if($this->isSecure()) {
            $this->markTestSkipped('This test needs an insecure instance of redis');
        }
        
        $storage = new RedisStorage($this->getRedisHost());
        $key = 'key';
        $data = ['foo' => 1, 'bar' => new \DateTime()];
        $storage->save($data, $key);
        self::assertEquals(Collection::make($data), $storage->get($key));
    }

You can find the workflow which I've created here https://github.com/zaherg/botman/blob/2.0/.github/workflows/test.yml and the results are here https://github.com/zaherg/botman/actions/runs/237445099 which is always connection refused (sadly)

if anyone can test it locally at his computer and share his finding that would be helpful too.

@zaherg
Copy link
Contributor

zaherg commented Sep 6, 2020

I updated my workflow to install redis-cli to verify that redis is working and can accept connections https://github.com/zaherg/botman/runs/1078750458?check_suite_focus=true, but I still got connections refused from the code.

@zaherg
Copy link
Contributor

zaherg commented Sep 7, 2020

@crynobone Done everything is green https://github.com/zaherg/botman/actions/runs/242493405

But these are the things I have found and the recommendation we need to do:

  1. The teardown function was missing the port which caused a connection refused whenever we finished a function.
  2. $_ENV is always empty due to the variables_order default values in github actions, so we needed to change that in the Setup PHP step, or maybe we should use dotenv package for development, or modify the code and use getenv instead.
  3. We need to split the authenticated tests from the one without authentication or add a function to skip the functions based on a variable called REDIS_SECURE like I did in my modifications.

Please review my code and if there is any question just let me know, my solution needs a refactoring from your end for sure but now we have a green tick as a start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants