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

Switching from offline back to online #40

Open
gingo opened this issue Dec 4, 2016 · 8 comments
Open

Switching from offline back to online #40

gingo opened this issue Dec 4, 2016 · 8 comments
Labels

Comments

@gingo
Copy link

gingo commented Dec 4, 2016

Hi there!

I have this two methods in my test-class:

public class ContentLoaderTest {

    @Test
    public void loadContent() throws Exception {

        // just for sure enable both internet connection types
        TestButler.setGsmState(true);
        TestButler.setWifiState(true);

        // place Thread.sleep(5000) here and everything is fine ;)

        // networking here is failing

    }

    @Test
    public void loadContentOffline() throws Exception {

        TestButler.setGsmState(false);
        TestButler.setWifiState(false);

        try {

            // networking here seems to be offline

        } finally {
            // enable it again
            TestButler.setGsmState(true);
            TestButler.setWifiState(true);
        }

    }

}

Method loadContentOffline() is started first and even if internet connectivity is reenabled again the second method is offline. It works with Thread.sleep().

@SKART1
Copy link
Contributor

SKART1 commented Mar 13, 2017

@gingo could you please add better description, looks like we are facing same problem

@drewhannay drewhannay added the bug label Mar 13, 2017
@gingo
Copy link
Author

gingo commented Mar 13, 2017

Please try to formulate question. What details do you need?

@SKART1
Copy link
Contributor

SKART1 commented Mar 14, 2017

the second method is offline

How can be a method "offline"? Is it about internet state?
How are you checking that internet is available?
Are you waiting for some condition or checking only once?

@gingo
Copy link
Author

gingo commented Mar 14, 2017

Yes, networking is failing as mentioned in comment. There is probably some delay when calling this methods:

    TestButler.setGsmState(true);
    TestButler.setWifiState(true);

I guess, TestButtler should wait before wifi is in desired state and then return from this methods.

@SKART1
Copy link
Contributor

SKART1 commented Mar 14, 2017

How are you checking that internet is available?

It takes some time for android OS to actually disable internet - so we are using something like this:

doEnable();
final ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

boolean result = PredicateWaiter.wait(RETRY_COUNT,
        new PredicateWaiter.DelayDependOnCount.SimpleLinearDelay(PAUSE_MS),
        new PredicateWaiter.Predicate() {
            @Override
            public boolean compute(int tryCount) {
                NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
                if (activeNetworkInfo == null) {
                    Log.d(TAG, "Predicate on " + tryCount + " is false because of activeNetworkInfo is null");
                } else if (activeNetworkInfo.isAvailable()) {
                    Log.d(TAG, "Predicate on " + tryCount + " is false because of activeNetworkInfo.isAvailable() is false");
                }
                return activeNetworkInfo != null && activeNetworkInfo.isAvailable();
            }
        });
if (!result) {
    throw new InternetManagerException("Internet was not enabled");
}

But sometimes internet do not coming back - even after 1 minute of waiting

@shatou-aqarmap
Copy link

I am having the same issue. The problem is that the test that disables the internet breaks down the following test although I am calling both setGsmState(true) and setWifiState(true) before the following tests. The only way to fix this for now is to test offline test in a separate test class.

@iank-wp
Copy link

iank-wp commented May 4, 2017

I'm having the exact same problem as well. The first test will shutoff the wifi, and then re-enable it to do some network calls (which are successful). However the next test will have network calls time out.

@kushsaini10
Copy link

I have made an Idling Resource to halt test until required connectivity state is met check it out here https://github.com/kushsaini10/connectivity-idling-resource

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

No branches or pull requests

6 participants