diff --git a/ncmb_unity/Assets/NCMB/Script/NCMBConnection.cs b/ncmb_unity/Assets/NCMB/Script/NCMBConnection.cs
index 0d46b2d5..184ae3cc 100644
--- a/ncmb_unity/Assets/NCMB/Script/NCMBConnection.cs
+++ b/ncmb_unity/Assets/NCMB/Script/NCMBConnection.cs
@@ -69,7 +69,7 @@ public class NCMBConnection
private static readonly string HEADER_USER_AGENT_VALUE = "unity-" + CommonConstant.SDK_VERSION;
// time out 10 sec
- private static readonly int REQUEST_TIME_OUT = 10;
+ // private static readonly int REQUEST_TIME_OUT = 10;
private string _applicationKey = "";
private string _clientKey = "";
@@ -86,6 +86,8 @@ public class NCMBConnection
private Uri _domainUri = null;
private NCMBFile _file = null;
internal UnityWebRequest _request = null;
+ // request time out
+ private int _requestTimeout = 10;
//コンストラクタ(通常)
@@ -101,7 +103,7 @@ internal NCMBConnection (String url, ConnectType method, string content, string
}
//コンストラクタ
- internal NCMBConnection (String url, ConnectType method, string content, string sessionToken, NCMBFile file, string domain)
+ internal NCMBConnection (String url, ConnectType method, string content, string sessionToken, NCMBFile file, string domain, int requestTimeout = 10)
{
this._method = method;
this._content = content;
@@ -112,6 +114,7 @@ internal NCMBConnection (String url, ConnectType method, string content, string
this._domainUri = new Uri (domain);
this._file = file;
this._request = _returnRequest ();
+ this._requestTimeout = requestTimeout;
}
@@ -399,7 +402,7 @@ internal static IEnumerator SendRequest (NCMBConnection connection, UnityWebRequ
while (!req.isDone) {
//elapsedTime += Time.deltaTime;
elapsedTime += waitTime;
- if (elapsedTime >= REQUEST_TIME_OUT) {
+ if (elapsedTime >= connection._requestTimeout) {
req.Abort ();
error = new NCMBException ();
break;
diff --git a/ncmb_unity/Assets/NCMB/Script/NCMBFile.cs b/ncmb_unity/Assets/NCMB/Script/NCMBFile.cs
index ae755b8d..a5e5d387 100644
--- a/ncmb_unity/Assets/NCMB/Script/NCMBFile.cs
+++ b/ncmb_unity/Assets/NCMB/Script/NCMBFile.cs
@@ -14,6 +14,9 @@ namespace NCMB
public class NCMBFile : NCMBObject
{
+ // Time out 120 sec
+ private static readonly int FILE_REQUEST_TIME_OUT = 120;
+
///
/// ファイル名の取得、または設定を行います。
///
@@ -100,7 +103,7 @@ public override void SaveAsync (NCMBCallback callback)
IDictionary currentOperations = null;
currentOperations = this.StartSave ();
string content = _toJSONObjectForSaving (currentOperations);
- NCMBConnection con = new NCMBConnection (_getBaseUrl (), type, content, NCMBUser._getCurrentSessionToken (), this);
+ NCMBConnection con = new NCMBConnection (_getBaseUrl (), type, content, NCMBUser._getCurrentSessionToken (), this, NCMBSettings.DomainURL, FILE_REQUEST_TIME_OUT);
con.Connect (delegate(int statusCode, string responseData, NCMBException error) {
try {
NCMBDebug.Log ("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData);
@@ -145,7 +148,7 @@ public void FetchAsync (NCMBGetFileCallback callback)
}
// 通信処理
- NCMBConnection con = new NCMBConnection (_getBaseUrl (), ConnectType.GET, null, NCMBUser._getCurrentSessionToken (), this);
+ NCMBConnection con = new NCMBConnection (_getBaseUrl (), ConnectType.GET, null, NCMBUser._getCurrentSessionToken (), this, NCMBSettings.DomainURL, FILE_REQUEST_TIME_OUT);
con.Connect (delegate(int statusCode, byte[] responseData, NCMBException error) {
NCMBDebug.Log ("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData);
this.estimatedData ["fileData"] = responseData;
diff --git a/ncmb_unity/Assets/PlayModeTest/MockServer.cs b/ncmb_unity/Assets/PlayModeTest/MockServer.cs
index 696c7574..ed6ed190 100644
--- a/ncmb_unity/Assets/PlayModeTest/MockServer.cs
+++ b/ncmb_unity/Assets/PlayModeTest/MockServer.cs
@@ -9,6 +9,7 @@
using System.Text;
using NCMB.Internal;
using System.Security.Cryptography;
+using System.Threading;
public class MockServer
{
@@ -32,7 +33,7 @@ public class MockServer
private static string DATA_PATH_DEFAULT = "PlayModeTest/mbaas.yaml";
//Dictionary to store all mock data
Dictionary> mockObjectDic = new Dictionary> ();
- Uri _domainUri = new Uri(NCMBTestSettings.DOMAIN_URL);
+ Uri _domainUri = new Uri(NCMBTestSettings.DOMAIN_URL);
public MockServer()
{
@@ -142,6 +143,11 @@ private void checkAndResponse (HttpListenerRequest request, HttpListenerResponse
string signature = _makeResponseSignature(request, mockObj.responseJson);
response.AddHeader("X-NCMB-Response-Signature", signature);
}
+
+ if(mockObj.delay > 0){
+ Thread.Sleep(mockObj.delay);
+ }
+
//Set status code
response.StatusCode = mockObj.status;
byte[] buffer = System.Text.Encoding.UTF8.GetBytes (mockObj.responseJson);
@@ -219,6 +225,12 @@ private void ReadMockData ()
mock.responseSignature = true;
}
+ if (response.Children.Keys.Contains(new YamlScalarNode("delay")))
+ {
+ YamlScalarNode delay = (YamlScalarNode)response.Children [new YamlScalarNode ("delay")];
+ mock.delay = Convert.ToInt32 (delay.Value);;
+ }
+
YamlScalarNode status = (YamlScalarNode)response.Children [new YamlScalarNode ("status")];
mock.status = Convert.ToInt32 (status.Value);
diff --git a/ncmb_unity/Assets/PlayModeTest/MockServerObject.cs b/ncmb_unity/Assets/PlayModeTest/MockServerObject.cs
index 3f392e14..27c2abcd 100644
--- a/ncmb_unity/Assets/PlayModeTest/MockServerObject.cs
+++ b/ncmb_unity/Assets/PlayModeTest/MockServerObject.cs
@@ -18,6 +18,7 @@ public class MockServerObject
public string responseJson = "";
public int status = 404;
public bool responseSignature = false;
+ public int delay = 0;
public void validate()
{
diff --git a/ncmb_unity/Assets/PlayModeTest/NCMBObjectTest.cs b/ncmb_unity/Assets/PlayModeTest/NCMBObjectTest.cs
index b0436ae8..fe5c6a52 100644
--- a/ncmb_unity/Assets/PlayModeTest/NCMBObjectTest.cs
+++ b/ncmb_unity/Assets/PlayModeTest/NCMBObjectTest.cs
@@ -68,5 +68,26 @@ public void GetBaseUrlTest ()
}
+ /**
+ * - 内容:タイムアウトのエラーをチェックする
+ * - 結果:保存の時にタイムアウトした。(error 408)
+ */
+ [UnityTest]
+ public IEnumerator SaveObjectTimeout ()
+ {
+ // テストデータ作成
+ NCMBObject obj = new NCMBObject ("TestClass");
+ obj ["key"] = "\"timeout-test\"";
+ obj.SaveAsync ((NCMBException e) => {
+ if (e != null && string.Compare("408", e.ErrorCode) == 0) {
+ Assert.True(true);
+
+ } else {
+ Assert.True (false);
+ }
+ NCMBTestSettings.CallbackFlag = true;
+ });
+ yield return NCMBTestSettings.AwaitAsync ();
+ }
}
\ No newline at end of file
diff --git a/ncmb_unity/Assets/PlayModeTest/mbaas.yaml b/ncmb_unity/Assets/PlayModeTest/mbaas.yaml
index 0c7c6a91..665c10ad 100644
--- a/ncmb_unity/Assets/PlayModeTest/mbaas.yaml
+++ b/ncmb_unity/Assets/PlayModeTest/mbaas.yaml
@@ -347,6 +347,16 @@ response:
status: 201
file: /json/post_success_response.json
---
+request:
+ url: 2013-09-01/classes/TestClass
+ method: POST
+ body:
+ key: \"timeout-test\"
+response:
+ status: 201
+ file: /json/post_success_response.json
+ delay: 12000
+---
request:
url: 2013-09-01/classes/TestClass
method: GET
@@ -428,6 +438,7 @@ request:
response:
status: 200
file: /json/create_date_response.json
+ delay: 12000
---
request:
url: 2013-09-01/files/test.txt
@@ -435,6 +446,7 @@ request:
response:
status: 200
file: /json/file_hello_response.json
+ delay: 12000
---
request:
url: 2013-09-01/users